实例 C++ 向类方法添加参数

x
 
#include <iostream>
using namespace std;
class Car {
  public:
    int speed(int maxSpeed);
};
int Car::speed(int maxSpeed) {
  return maxSpeed;
}
int main() {
  Car myObj;
  cout << myObj.speed(200);
  return 0;
}
                    

输出结果

200