here is my codes, i plan to output the name and the weight.
but no matter i try many time it still give me an output only
output should be this->
Name = Meow
Weight = 10.5
whereas what am I getting is
Weight = 10.5, why?
thx
#include <iostream>
using namespace std;
class Animal {
string name;
public:
Animal (string name)
: name(name) {}
void print() const {
cout << "Name = " << name << endl;
}
};
class Cat : public Animal{
double weight;
public:
Cat(string name, double weight)
: Animal(name), weight(weight) {this-> weight = weight;}
void print() const {
cout << "Weight = " << weight << endl;
}
};
int main() {
Cat c("Meow", 10.5);
c.print();
return 0;
}