我創建了2個類,分支和帳戶,並且我希望我的Branch類具有一個帳戶指針數組,但我無法執行此操作。它說「不完整的類型是不允許的」。我的代碼有什麼問題?嘗試創建指針數組時不允許使用不完整類型
#include <string>
#include "Account.h"
using namespace std;
class Branch{
/*--------------------public variables--------------*/
public:
Branch(int id, string name);
Branch(Branch &br);
~Branch();
Account* ownedAccounts[]; // error at this line
string getName();
int getId();
int numberOfBranches;
/*--------------------public variables--------------*/
/*--------------------private variables--------------*/
private:
int branchId;
string branchName;
/*--------------------private variables--------------*/
};
數組在編譯時是否已知大小?另外,你確定你需要'Account'指針,而不僅僅是對象嗎? – chris 2013-04-05 01:22:11
開始時數組的大小爲0,我將動態擴展它。是的,我需要帳戶指針,因爲帳戶對象的數組是在另一個文件,我需要指出它也從另一個類名爲客戶。 – 2013-04-05 01:27:04
我不明白你的意思。首先,你可以使用一個'std :: vector'來完成調整大小和一切。關於你的結構,如果'Customer.h'和'Branch.h'包含'Account.h',它們都可以使用普通對象。沒有指針需要。 – chris 2013-04-05 01:33:33