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++書籍和教程都有例子。 –
這同樣適用於構造函數嗎? –