D
Dave
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.
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.