O'Reilly logo
  • Yuan Peng Chiang thinks this is interesting:

3: class SimpleCat
 4: {
 5: public:
 6:     SimpleCat();
 7:     SimpleCat(SimpleCat&);
 8:     ~SimpleCat();
10:     int GetAge() const { return itsAge; }
11:     void SetAge(int age) { itsAge = age; }
13: private:
14:     int itsAge;
15: };


Cover of Sams Teach Yourself C++ in 24 Hours, fifth edition


Class declaration: A declaration introduces an identifier and describes its type, be it a type, object, or function. A declaration is what the compiler needs to accept references to that identifier. These are declarations:

extern int bar; extern int g(int, int); double f(int, double); // extern can be omitted for function declarations class foo; // no extern allowed for class declarations

A definition actually instantiates/implements this identifier. It's what the linker needs in order to link references to those entities. These are definitions corresponding to the above declarations:

int bar; int g(int lhs, int rhs) {return lhs*rhs;} double f(int i, double d) {return i+d;} class foo {};