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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!