Re: organising classes c++
From: Josh Sebastian (curien_at_cox.net)
Date: 11/19/03
- Next message: Josh Sebastian: "Re: property operator"
- Previous message: Jason: "organising classes c++"
- In reply to: Jason: "organising classes c++"
- Next in thread: jeffc: "Re: organising classes c++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 19 Nov 2003 17:50:40 -0500
On Wed, 19 Nov 2003 22:44:54 +0000, Jason wrote:
> hello,
>
> How do I organise my classes in c++? At the moment I have something like
> this in a .cpp file
>
> class classname { //class definition
> private:
> //...
> public:
> //...stuff
> char getchar();
> }
>
> char classname::classname getchar() {
> return anyhing;
> }
>
> and then in a separate header file I placed a copy of the class definition -
> obviously not the function implementations.
>
> Is that how classes make their interfaces known to other classes so a class
> in another file just includes <"classname.h">. Must I have a separate
> header file to the main .cpp file in order to create associations? Does the
> main .cpp file have to include the class definition here and in the header
> file? When you have lots of classes how do most c++ programmers organise
> them, just as described or different?
>
> I would be grateful for any comments as I just want to be clear on these
> points.
Put the class definition in a header file (say, class.h) and put the
function definitions in a source file (say, class.cpp). Then include the
header in any source file that needs to use the class. Also, just include
class.h at the beginning of class.cpp (no need to duplicate it).
If you have several classes that depend on one another, you can put them
in the same header if you want. Basically, do whatever makes life easier
for people using your classes.
Josh
- Next message: Josh Sebastian: "Re: property operator"
- Previous message: Jason: "organising classes c++"
- In reply to: Jason: "organising classes c++"
- Next in thread: jeffc: "Re: organising classes c++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|