Newbie C++ Question

From: Dave (ihatespam_at_nospam.net)
Date: 11/19/04


Date: Fri, 19 Nov 2004 14:05:21 -0500

Hi All,

I have a question regarding using multiple CPP source files.

I have a class, "Mammal.cpp" that contains different member variables and
functions. I now want to create several classes, each in its own source
file, that use "Mammal" as a base class. What's the best way of doing this?
If I #include the entire "Mammal.cpp" file into my new classes the compile
works....but I don't think that this would be considered a Best Practice.

I've seen examples in C where people create a Header file and place variable
and function declarations in it. Does it work the same way in C++? Do I
simply copy "Mammal.cpp" to "Mammal.h" and then delete the implementation
(leaving just the Class declarations)? Assuming this is my base class,
"Mammal.cpp":

class Mammal {
  private:
    int age;

  public:
    int getAge() {return age; }
    void setAge(int x) { age = x; }

  Mammal::Mammal(int x) {
    age = x;
  }

};

What would the "Mammal.h" file contain?

Thanks in advance.