Declaring and implementing methods

Dear All,
What is the best practice for writing classes:
Should implementation of methods be inside the body of the class or should be defined separately?
If yes should the implementation be in the same file or in some other?
Should classes be defined in header or source files?
Is it good practice to define more than one class in a header (source) file?
Thank in advance
[397 byte] By [lontana] at [2007-11-20 11:57:43]
# 1 Re: Declaring and implementing methods
Should implementation of methods be inside the body of the class or should be defined separately?Generally speaking, defined separately - unless the implementation is very simple.

Should classes be defined in header or source files?Usually you declare classes in header files and implement them in source files. However, there are some occasions (e.g. template classes) where the implementation needs to be in the header file.

Is it good practice to define more than one class in a header (source) file?This is partly a matter of taste but you need to be aware that one of the main uses of a C++ class is to describe an object (hence the term Object Oriented Programming - or OOP). It's often most convenient to describe each object in a single header file and a single source file but there's no 'rule' about it. In fact, everything I've described is really a generalisation.
John E at 2007-11-11 4:01:52 >