[英]How to add ALL elements from one class to an array of another class
class Airplane{
public:
string airplaneName;
string captainName;
string copilotName;
int passangerNumber;
bool captain;
bool copilot;
};
class Fleet{
public:
string fleetName;
Airplane airplaneFleet;
};
所以我必須將飛機(實際上是幾架飛機)中的所有元素添加到一個機隊中,我該怎么做。 我已經嘗試了不同的代碼,但我什至沒有關閉,如果您有一些解決方案,請解釋一下,謝謝!
根據這個問題,您可以擁有一個已定義大小的數組,也可以擁有一個可以在運行時向其中添加元素的vector
。
Airplane airplanesInFleet[10]; // Fixed - 10 airplans
std::vector<Airplane> airplanesInFleet; // Dynamic - use 'push_back' to add airplane
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.