我有 1 个主要课程
class Vehicle{
private:
int fuel;
public:
int get_fuel(){ return this->fuel; }
void set_fuel(int fuel){ this->fuel = fuel; }
};
也是车辆的 1 个子类
class Car : public Vehicle{
public:
Car();
};
Car::Car(){
set_fuel(500);
}
还有我的main.cpp文件
#include <cstdlib>
#include <iostream>
#include "Vehicle.h"
#include "Car.h"
using namespace std;
int main(int argc, char *argcv[]){
Car c;
cout << c.get_fuel() << endl; //500
//set fuel to 200
c.set_fuel(200);
//print fuel again
cout << c.get_fuel() << endl;//still 500
}
为什么在使用 setter 后值在我使用 getter 后仍然保持不变?