How many c++ classes per file

Started by
11 comments, last by smart_idiot 18 years, 1 month ago
What is the advantage of making a .cpp file to implement the .h if you are not including it inside the .h, but adding it to the project? I feel it is way better to do as I mentioned, since you can never have the implementation file without the declaration file.

// file.h#ifndef FILE_H#define FILE_Hclass SomeClass{    // ...};#include "file.impl"#endif

// file.implSomeClass::SomeClass(){    // ...}// ...


That's how I do.
Advertisement
If you put a .cpp file instead of a .impl file like you do, the compiler recognizes it as a compilation unit. Files ending in .cpp are compiled, otherwise the compiler might ignore the code in your .impl file.

The only time I could think of where you would make a .impl file is if you're trying to separate the implementations of templated functions; most compilers can't handle having them in a separate compilation unit.
Kalazart's example should result in a link time error if it's included by more than one file. If SomeClass was a template, then that would be an okay way to do things.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

This topic is closed to new replies.

Advertisement