0
宁可自我解释。我只是想知道在面向对象的C++中做什么更传统?在C++中,定义类定义内部还是外部的方法体更为常规?
实例A:
class CarObject{
private: //Local Variables
string name;
int cost;
public:
CarObject(string pName, int pCost){ //Constructor with parameters of car name and car cost
name = pName; //Sets the temporary variables to the private variables
cost = pCost;
}
void getDetails(){
cout << name;
cout << cost;
}//Public method that returns details of Car Object
};
例B:
class CarObject{
private: //Local Variables
string name;
int cost;
public:
CarObject(string pName, int pCost){ //Constructor with parameters of car name and car cost
name = pName; //Sets the temporary variables to the private variables
cost = pCost;
}
void getDetails(); //Public method that returns details of Car Object
};
void CarObject :: getDetails(){
cout << name;
cout << cost;
}
外面,除非模板化。 – ChiefTwoPencils
你有没有看过任何C++代码?遍及互联网和每本C++书籍和教程都有例子。 –
这同样适用于构造函数吗? –