I don't know how to sparate the interface and their implement.And I need some help from you.For example,I hope anybody can tell me,how to make these three files to work well.

//This file named main.cpp
#include <iostream>
#include "ABC.h"
using namespace std;
int main(void)
{
    char y='y';
    char e='e';
    char s='s';
    ABC yes(y,e,s);
    
    yes.read_a()='t';
    //yes.read_c()='p';
    cout<<yes.read_a()<<yes.read_b()<<yes.read_c();
}
//This file named ABC.h
#ifndef ABC_H
#define ABC_H
#include "ABC.cpp"

class ABC{
public:
       ABC(char inita=0,char initb=0,char initc=0)
       :a(inita),b(initb),c(initc){  }
       
       char& read_a();
       char& read_b();
       const char& read_c();
       
protected:
        char a;
        char b;
        char c;
};
 
#endif
//This file named ABC.cpp which implement the interface from ABC.h
#ifndef ABC_H
#define ABC_H
#include "ABC.cpp"

class ABC{
public:
       ABC(char inita=0,char initb=0,char initc=0)
       :a(inita),b(initb),c(initc){  }
       
       char& read_a();
       char& read_b();
       const char& read_c();
       
protected:
        char a;
        char b;
        char c;
};
 
#endif

Thanks for anybody who help me!My English is poor,I hope that you can understand the means of mine^_^

I don't know how to sparate the interface and their implement.And I need some help from you.For example,I hope anybody can tell me,how to make these three files to work well.

//This file named main.cpp
#include <iostream>
#include "ABC.h"
using namespace std;
int main(void)
{
    char y='y';
    char e='e';
    char s='s';
    ABC yes(y,e,s);
 
    yes.read_a()='t';
    //yes.read_c()='p';
    cout<<yes.read_a()<<yes.read_b()<<yes.read_c();
}
//This file named ABC.h
#ifndef ABC_H
#define ABC_H
#include "ABC.cpp"
 
class ABC{
public:
       ABC(char inita=0,char initb=0,char initc=0)
       :a(inita),b(initb),c(initc){  }
 
       char& read_a();
       char& read_b();
       const char& read_c();
 
protected:
        char a;
        char b;
        char c;
};
 
#endif
//This file named ABC.cpp which implement the interface from ABC.h
#ifndef ABC_H
#define ABC_H
#include "ABC.cpp"
 
class ABC{
public:
       ABC(char inita=0,char initb=0,char initc=0)
       :a(inita),b(initb),c(initc){  }
 
       char& read_a();
       char& read_b();
       const char& read_c();
 
protected:
        char a;
        char b;
        char c;
};
 
#endif

Thanks for anybody who help me!My English is poor,I hope that you can understand the means of mine^_^

Ok, you've got a good start, but a few things...the ABC.cpp file you posted is exactly the same as the ABC header file...get rid of the class definition from the ABC.cpp file and just write the function definitions from you ABC header file...
second...your ABC.cpp file should not have ifndef, define or endif statements...all you need to do is include the ABC.h file (and any other header files that may be required)...
third...you do not need to include the ABC.cpp file in your ABC.h file...include the header file in your .cpp file will be sufficient...
Hope this gets you pointed in the right direction...
cheers!

//I'm sorry for that the ABC.cpp file is the following file,not that I
//posted. It's a error when I copy it. I'm sorry for that!
#include "ABC.h"

char & ABC::read_a(){
return a;
}

char & ABC::read_b(){
return b;
}

const char & ABC::read_c(){
return c;
}

Thanks to you for help me!

Now the codes should works well. But I have another question: How to make my ABC.h work like the head files from the standard library?

When I compile my code,I must imput the command like this(using Dev-cpp compiler):

g++ -o main.exe main.cpp ABC.h ABC.cpp

Now,I want to make them work only need to input :

g++ -o main.exe main.cpp

or

g++ -o main.exe main.cpp ABC.h

Never let ABC.cpp appear in the compile command.
Then how should I do?
Thank you!

The format you are using for includes will work only if all the files are in the the same directory as the main.cpp. Otherwise, state the full path name whee the compiler can find them.

#include "/full/path/name/ABC.h"

I think you can simplify things further by just specifying the output file name without the exe.
I believe that is automatically added.

g++ -o main main.cpp

I do more with linux and the GNU compiler than windows.
I also use a different IDE called codeblocks, but the basic rules should apply to all.

The format you are using for includes will work only if all the files are in the the same directory as the main.cpp. Otherwise, state the full path name whee the compiler can find them.

#include "/full/path/name/ABC.h"

I think you can simplify things further by just specifying the output file name without the exe.
I believe that is automatically added.

g++ -o main main.cpp

I do more with linux and the GNU compiler than windows.
I also use a different IDE called codeblocks, but the basic rules should apply to all.

GUN should not pass the command:
g++ -o main main.cpp
like you said.

I also love GUN linux compiler than windows.Isn't Dev-cpp also a kind of GUN compiler?

Thanks

Dev-cpp is an IDE (Integrated Development Environment).
One of the components of it is the compiler.
I understand that bloodshed is a bit "quirky" at times.

Codeblocks was recommended to me by seasoned professionals on this site.
they offer a NATIVE windows version which also allows you to select whatever compiler you want to use.

I have used it with good results on windows and Linux. In fact, some of the GUI project wizards work better on windows. for example, QT4 works well on the windows version, but is a disaster in the Linux version.

Did you fix you "include' problem?

Dev-cpp is an IDE (Integrated Development Environment).
One of the components of it is the compiler.
I understand that bloodshed is a bit "quirky" at times.

Codeblocks was recommended to me by seasoned professionals on this site.
they offer a NATIVE windows version which also allows you to select whatever compiler you want to use.

I have used it with good results on windows and Linux. In fact, some of the GUI project wizards work better on windows. for example, QT4 works well on the windows version, but is a disaster in the Linux version.

Did you fix you "include' problem?

Yes,thank you.I have fixed it.
I know not Dev-cpp could also used well in Linux.
In windows, I consider that it is a kind of GNU compiler which used gcc3.4 version.

I come from China,so my English is poor.
I hope anybody can point out my errors in English,when you help me,thanks^_^

This article has been dead for over six months. Start a new discussion instead.