Class Design: Multiple Classes in one File


Is it good style to use more than one class in a single file?

E.g. there is a file calculator.cpp and there is
a class calc_addition and a class calc_division in it.

Would it be a better style to have one class in one file?

Thanks for help.
> there is a file calculator.cpp and there is a class calc_addition and a class calc_division in it.

Should calc_addition and a class calc_division be classes?
Or should it be that we have a class calculator which has operations add and divide?

In general, if two reasonably small classes are implemented together (by the same person), debugged together, tested together and would always be used together, it would be silly to have the two classes in two different components. (For example, a list class and the iterator for that list class would be in the same component; one may be the friend of the other.)

Otherwise, one class, one component would be right.

Note that in C++ we have a separate compilation model; unlike in Java, a component in C++ is often a pair of files - the header (.h) and the implementation (.cpp).
Topic archived. No new replies allowed.