我这里有一些代码从文件中读取,并将它们存储在一个向量中。
我希望将此向量传递给另一个类。但是,当我尝试这样做时,它给了我一个奇怪的错误,我不完全理解。似乎是说没有声明向量。
以下是很长时间错误的前几行:
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>)’
这是第282行 - C_HomePage.cpp第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;
};
老实说,我不知道出了什么问题,已经花了很多时间对它感到沮丧。有人可以帮忙吗?
答案 0 :(得分:1)
您在getDutiesList
和getResourcesList
的声明中缺少括号:
vector<string> getDutiesList();
vector<string> getResourcesList();
编辑:您还缺少.cpp文件中的括号:
vector<string> HomePage::getResourcesList(){
return resourcesList;
}