Re: organising classes c++
From: Jason (jason.carney1_at_btinternet.com)
Date: 11/20/03
- Next message: Jason: "Re: organising classes c++"
- Previous message: ellie fant: "Re: Top ten errors"
- In reply to: David White: "Re: organising classes c++"
- Next in thread: Jason: "Re: organising classes c++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 19 Nov 2003 23:21:16 +0000 (UTC)
"David White" <no@email.provided> wrote in message
news:LISub.1783$xm.87676@nasal.pacific.net.au...
> "Jason" <jason.carney1@btinternet.com> wrote in message
> news:bpgrp5$970$1@sparta.btinternet.com...
> > 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();
> > }
>
> Place this in your header file only, and #include the header in this
source
> file. Unless the class is used in only one source file, put it in a header
> file.
>
> > char classname::classname getchar() {
> > return anyhing;
> > }
>
> Placing this in a source file (.cpp in your case) is correct. However, any
> member functions that you want inline need to be in the header file -
either
> within the class definition itself or with the 'inline' keyword outside
the
> class.
>
> > and then in a separate header file I placed a copy of the class
> definition -
> > obviously not the function implementations.
>
> Don't make copies of class definitions. Any changes that you want to make
> will have to made in two places. Just include the header that contains the
> single definition, as explained above.
>
> > Is that how classes make their interfaces known to other classes so a
> class
> > in another file just includes <"classname.h">.
>
> Use ONE of <> and "", not both. Use <> for system headers and "" is for
your
> own, e.g.,
>
> #include <string>
> #include "MyClass.h"
>
> > Must I have a separate
> > header file to the main .cpp file in order to create associations?
>
> What do you mesan by associations?
sorry to use jargon, by association i just meant making a class known to
another class such as by including one object as an attribute of another
object. So the question was does the class definition have to be in a
separate header file to be visible to the outside world, but that question
has already been answered by yours and others responses so thanks.
>
> > Does the
> > main .cpp file have to include the class definition here and in the
header
> > file?
>
> A program doesn't have to have a main.cpp. It just has to have a 'main'
> function. You can put this function anywhere and there are no special
rules
> regarding header files for it. You #include header files in any source
file
> when the source file needs them. That's all.
>
> > When you have lots of classes how do most c++ programmers organise
> > them, just as described or different?
>
> Some people use the convention of one class per source file, but I think
> that's too rigid. I'll often put closely related classes in the same file.
> There are no rules for this. Just use common sense.
>
> DW
>
>
>
- Next message: Jason: "Re: organising classes c++"
- Previous message: ellie fant: "Re: Top ten errors"
- In reply to: David White: "Re: organising classes c++"
- Next in thread: Jason: "Re: organising classes c++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|