无法将引用从一个类传递到另一个类

Unable to pass reference from one class to another

本文关键字:一个 另一个 引用      更新时间:2023-10-16

我正在编写一个c++程序,用于管理一个单位中的资源和职责。此程序旨在在Linux Shell中运行。

我创建了一个类调用主页供用户登录。我还有另一个类叫SelectionPage。这些是用户登录后的菜单。在我的主函数中,我希望将主页类的一个实例获得的一些数据传递给SelectionPage类的一个实例。

我被困在这里至少6个小时了,有人能帮帮我吗?

错误信息如下:

g++ C_Main.cpp C_HomePage.cpp C_SelectionPage.cpp -o Project
C_Main.cpp: In function ‘int main()’:
C_Main.cpp:17:93: error: no match for call to ‘(std::vector<std::basic_string<char> >) ()’
C_Main.cpp:17:122: error: no match for call to ‘(std::vector<std::basic_string<char> >) ()’
C_HomePage.cpp:290:41: error: no ‘std::vector<std::basic_string<char> > HomePage::getDutiesList()’ member function declared in class ‘HomePage’
C_HomePage.cpp:294:44: error: no ‘std::vector<std::basic_string<char> > HomePage::getResourcesList()’ member function declared in class ‘HomePage’
C_SelectionPage.cpp:9:144: error: declaration of ‘SelectionPage::SelectionPage(std::string, int, std::vector<std::basic_string<char> >, std::vector<std::basic_string<char> >, std::string)’ outside of class is not definition
C_SelectionPage.cpp:9:146: error: expected unqualified-id before ‘{’ token
make: *** [Project] Error 1

这是我的main()

// Testing Home Page Functionality
#include "H_HomePage.h"
#include "H_SelectionPage.h"
using namespace std;
string initializationFile = "D_initialization.dat";
string flatMemberFile = "D_flatMember.dat";
    int main()
       {
        HomePage frontEnd(initializationFile);             //Create Boundary Object
        system("clear");                                //Clear Terminal Screen
        frontEnd.login(flatMemberFile);
    SelectionPage Menu(frontEnd.getManager(), frontEnd.getInitPoints(), frontEnd.getDutiesList(), frontEnd.getResourcesList(), frontEnd.getLoginName());
      Menu.showManagerMenu();
        return 0;
       }

这是我的SelectionPage类的构造函数,如头文件中所述:

...
SelectionPage(string Manager, int Points, vector <string> dutiesList, vector <string> resourceList, string loginName);
...

下面是SelectionPage类构造函数的实现:

    SelectionPage::SelectionPage(string newanager, int points, vector <string> newDutiesList, vector <string> newResourceList, string newLoginName);{
    manager = newManage;
    initPoints = points;
    dutiesList = newDutiesList;
    resourceList = newResourceList;
    loginName = newLoginName;
}

有人能帮帮我吗?我会感激不尽的!

仔细查看错误信息。

C_HomePage.cpp:290:41: error: no ‘std::vector<std::basic_string<char> > HomePage::getDutiesList()’ member function declared in class ‘HomePage’
C_HomePage.cpp:294:44: error: no ‘std::vector<std::basic_string<char> > HomePage::getResourcesList()’ member function declared in class ‘HomePage’

您可能对HomePage::getDutiesList()HomePage::getResourcesList()有不正确的声明,或者根本没有。如果不查看类声明,很难判断它们究竟出了什么问题。这也是你的main()编译错误的原因。

其他两个编译错误的原因可能是){' in the definition of之间的虚假; SelectionPage::SelectionPage '。把它删掉

相关文章: