gpt4 book ai didi

c++ - 为什么编译器告诉我 vector 未声明?

转载 作者:行者123 更新时间:2023-11-28 08:15:24 25 4
gpt4 key购买 nike

我这里有一些代码可以从一个文件中读取,并将它们存储在一个 vector 中。

我希望将这个 vector 传递给另一个类。但是,当我尝试这样做时,它给了我一个奇怪的错误,我不完全理解。好像是说vector is not declared。

这是一个很长的错误的前几行:

 g++ C_Main.cpp C_HomePage.cpp C_SelectionPage.cpp -o Project
C_HomePage.cpp:286:40: error: no ‘std::vector<std::basic_string<char> > HomePage::getDutiesList()’ member function declared in class ‘HomePage’
C_HomePage.cpp:290:26: error: ‘std::vector<std::basic_string<char> > HomePage::getResourcesList’ is not a static member of ‘class HomePage’
C_HomePage.cpp:290:26: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
C_HomePage.cpp:291:2: error: expected primary-expression before ‘return’
C_HomePage.cpp:291:2: error: expected ‘}’ before ‘return’
C_HomePage.cpp:291:2: error: in C++98 ‘HomePage::getResourcesList’ must be initialized by constructor, not by ‘{...}’
C_HomePage.cpp:291:2: error: no matching function for call to ‘std::vector<std::basic_string<char> >::vector(<brace-enclosed initializer list>)’

这里是C_HomePage.cpp的282-292行

int HomePage::getInitPoints(){ 
return initPoints;
}

vector<string> HomePage::getDutiesList(){
return dutiesList;
}

vector<string> HomePage::getResourcesList{
return resourcesList;
}

H_HomePage.h 中这些方法的对应声明

class HomePage {
//These values will be the property of the flat
//They are set before the login screen is displayed
string manager;
int initPoints;
vector<string> dutiesList;
vector<string> resourcesList;
vector<FlatMember> flatMemberList;
string loginName;


public:

HomePage(string);

void login(string);
string receivePassword();

void importFlatMembers(string);
void exportFlatMembers(string);

string getLoginName();
string getManager();
int getInitPoints();
vector<string> getDutiesList;
vector<string> getResourcesList;

};

老实说,我不知道出了什么问题,并且已经花了很多时间为此感到沮丧。有人可以帮忙吗?

最佳答案

您在 getDutiesListgetResourcesList 的声明中缺少括号:

vector<string> getDutiesList();
vector<string> getResourcesList();

编辑:您还缺少 .cpp 文件中的括号:

vector<string> HomePage::getResourcesList(){
return resourcesList;
}

关于c++ - 为什么编译器告诉我 vector<string> 未声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7858598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com