【发布时间】:2014-12-22 16:03:12
【问题描述】:
我想创建一个 Accounts 对象数组,以便管理它们从文件中加载所有内容(通过结构)。 我很新学习 c++,但我不知道我做错了什么。
做什么:Account** accounts[50] ?
""accounts[i] = new Account*;
""accounts[i]->newAccount(i, id_string, pw_string, level_int);
错误消息:request for member 'newAccount' in '* accounts[i]', which is of non-class type 'Account*'
AccountManagerFrm.cpp // 运行一切的主文件
#include "AccountManagerFrm.h"
#include "Account.h"
#include "ladeAccounts.h"
using namespace std;
Account** accounts [50];
void AccountManagerFrm::createAccountClick(wxCommandEvent& event)
{
accounts[i] = new Account*;
accounts[i]->newAccount(i, id_string, pw_string, level_int); // ERROR LINE
}
帐户.cpp
class Account
{
struct iAccount
{
string ID;
string password;
int level;
};
Account()
{
}
void newAccount(int anzahl, string username, string pw, int lvl)
{
iAccount neu;
neu.ID = username;
neu.password = pw;
neu.level = lvl;
}
};
帐户.h
#include <string>
using namespace std;
class Account{
public:
Account();
void newAccount(int anzahl, string username, string pw, int lvl);
void getInformationFromFile();
};
【问题讨论】:
-
Accounts[i]是指向Account*的指针,而不是Account*。