organising classes c++

From: Jason (jason.carney1_at_btinternet.com)
Date: 11/19/03


Date: Wed, 19 Nov 2003 22:44:54 +0000 (UTC)

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.

Thanks in advance for your help :)



Relevant Pages

  • organising classes in c++?
    ... How do I organise my classes in c++? ... and then in a separate header file I placed a copy of the class definition - ... header file to the main .cpp file in order to create associations? ...
    (comp.lang.cpp)
  • Common Environment Object Model: getting the path to the cpp file a certain class is implemented in
    ... Say we have a CodeClass object and call AddFunction() on it. ... the call will end up with the function declaration ... in the header file for that class and the implementation in the cpp file. ...
    (microsoft.public.vsnet.general)
  • Re: Novice - Advice required
    ... > a seperate .cpp file (or header file?) and then whenever I want to ... int XYX::doTask ...
    (microsoft.public.vc.language)
  • Re: C++ header file
    ... Why not just have 1 CPP file and include the CPP file instead of ... In Java, there is no header file, each object is .java file. ... Separation of declaration and definition is very practical thing. ... It is sufficient to see only function's declaration in order to successfully compile a code that calls it. ...
    (microsoft.public.vc.language)
  • Re: Importing a type library into unmanaged code with /clr switch - linker errors
    ... I made some progress by just enabling /clr on the module (cpp file) ... but when I add managed code into the header file like: ... I get the compiler error: ...
    (microsoft.public.dotnet.languages.vc)