所以我試圖定義一個類,我正在使用另一個類的另一個數組來定義它。C++:在嵌套類定義(OOP)中使用數組
//header file for Name.h
class Name {
string last;
string first;
};
//header file for Depositor.h
class Depositor {
Name name;
string ssn;};
//header file for Account.h
class Account {
Depositor depositor;
int acctnum;
string type;
double balance;
};
//header file for Bank.h
#include "Account.h"
class Bank {
Account account[]; //is this possible?
int active_accts;
};
當我編寫cpp文件時,我遇到了很多問題!
//example of mutator
void Bank::setLastname(string lastname)
{
account.setLastname (lastname);
}
我不包括我寫入頭文件的存取器和acessors,但它們的存在,並會公開 - 它不會編譯。 你能幫忙嗎?在Bank.h中使用一個類的數組甚至是有效的嗎?
當然,一個成員數組的大小可以通過*非類型模板參數指定*。這就是[Boost.Array](http://www.boost.org/doc/libs/release/doc/html/array.html)的工作原理。 – 2011-02-16 03:23:42
@In:當然,但它仍然是類型的一部分; `boost :: array`下的數組的維數爲3:它是已知的並且是固定的,`boost :: array `是與`boost :: array `不同的類型`。 –
2011-02-16 03:32:12
對。 OP在編譯期間的某個時間仍然需要提供數組的大小。 – 2011-02-16 03:36:01