在尝试创建指针数组时,不允许使用不完整类型
incomplete type is not allowed while trying to create an array of pointers
我创建了2个类,分支和帐户,我希望我的分支类有一个帐户指针数组,但我没有做到这一点。上面写着"不完整的类型是不允许的"。我的代码有什么问题?
#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 **ownedAccounts;
...
// Later on, in the constructor
ownedAccounts = new Account*[numOwnedAccounts];
...
// Later on, in the destructor
delete[] ownedAccounts;
你需要指定数组的大小…你不能就这样把括号挂起来,里面什么也没有
相关文章:
- C++从外部类继承的嵌套类;不允许使用不完整的类型
- 数组错误(不允许类型不完整)
- 类中不允许使用不完整的类型,但在类模板中允许使用不完整的类型
- AActor *UactorComponent::GetOwner const - 不允许指向不完整类类型的指针
- 不允许使用不完整的类型
- C++ - 声明结构和类时不允许使用不完整的类型
- 虚幻引擎 4.18.0,VS2017,不允许指向不完整类类型的错误指针
- 分部模板类中不允许指向不完整类类型的指针
- PCL :: PointXyz不允许使用不完整的类型
- 我的库中有多个类:不允许使用不完整的类型
- 错误:不允许指向不完整类类型的指针.我该怎么做
- 不允许指向不完整类类型的指针
- 错误:不允许指向不完整类类型的指针
- 不允许指向不完整类类型的指针.(与相互引用的类相结合.)
- 不允许使用不完整类型的推力copy_if
- 使用类类型的向量进行前向声明——不允许指向不完整类类型的指针
- 在尝试创建指针数组时,不允许使用不完整类型
- 不允许指向不完整类类型的c++指针
- 错误,不允许类型不完整
- 类构造函数:不允许类型不完整(在成员列表中)-VS C++w/QT