Question: Take the following code: class Dog { private: double mWeight; public: Dog() : mWeight(1.0) {} void setWeight(double weight) { mWeight = weight; } double getWeight()
Take the following code:
class Dog {
private:
double mWeight;
public:
Dog()
: mWeight(1.0)
{}
void setWeight(double weight) {
mWeight = weight;
}
double getWeight() {
return mWeight;
}
};
void changeDogWeight(Dog dog) {
dog.setWeight(25.0);
}
void main() {
Dog myDog = Dog();
changeDogWeight(myDog);
cout << "The dog's weight: " << myDog.getWeight();
}
When the code above is executed, we get the following message:
The dog's weight: 1.0
Why is the dog's weight not 25.0?
C++
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
