【问题标题】:error LNK2019: unresolved external symbol referenced in function _main visual c++错误 LNK2019:函数 _main visual c++ 中引用的未解析的外部符号
【发布时间】:2013-06-02 21:12:29
【问题描述】:

有人对如何解决这个问题有任何想法吗?我在网上查看并更改了我的 Visual C++ 的设置,但它仍然无法正常工作。

class store
{
public:
    int MainMenu();
    store();
private:
    int main;
};

class customer:store
{
public:
    int CustomerMenu();
    customer();
private:
    int cmenu;
};

class employee:store
{
public:
    int EmployeeMenu();
    employee();
private:
    int emenu;

};

int main()
{
    int main;
    store a;
    customer b;
employee c;
a.MainMenu();
if(main = 1)
{
    c.EmployeeMenu();
}
else if(main = 2)
{
    b.CustomerMenu();
}
else
{
    exit(EXIT_SUCCESS);
}
}

int MainMenu()
{
    int main;
cout << "Choose an option: " << endl;
cout << " 1. Administration menu" << endl;
cout << " 2. Customer menu" << endl;
cout << " 3. Exit the program" << endl;
cin >> main;
return main;
}

int CustomerMenu()
{
int cmenu;
cout << " 1. Search Video" << endl;
cout << " 2. View Video Titles" << endl;
cout << " 3. Rent Video" << endl;
cout << " 4. Exit to the Main Menu" << endl;
cout << " 5. Exit the program" << endl;
cin >> cmenu;
return cmenu;

}

int EmployeeMenu()
{
int emenu;
    cout << " 1.  Store Information menu" << endl;
    cout << " 2.  Merchandise Information menu" << endl;
    cout << " 3.  Category Information menu" << endl;
    cout << " 4.  Customer Information menu" << endl;
    cout << " 5.  Employee Information menu" << endl;
    cout << " 6.  Rent a Video" << endl;
    cout << " 7.  Restock Video" << endl;
    cout << " 8.  Sales menu" << endl;
    cout << " 9.  Exit to Main Menu" << endl;
    cout << " 10. Exit the program" << endl;
cin >> emenu;
return emenu;

}

store::store()
{
main = 0;
}

customer::customer()
{
cmenu = 0;
}

employee::employee()
{
emenu = 0;
}

它给了我:

Store.obj : error LNK2019: unresolved external symbol "public: int __thiscall customer::CustomerMenu(void)" (?CustomerMenu@customer@@QAEHXZ) referenced in function _main
1>Store.obj : error LNK2019: unresolved external symbol "public: int __thiscall employee::EmployeeMenu(void)" (?EmployeeMenu@employee@@QAEHXZ) referenced in function _main
1>Store.obj : error LNK2019: unresolved external symbol "public: int __thiscall store::MainMenu(void)" (?MainMenu@store@@QAEHXZ) referenced in function _main

【问题讨论】:

  • 为什么会有一个变量叫main
  • 更不用说if (main = 1) 永远是真的。你的意思是==

标签: c++ visual-c++ lnk2019


【解决方案1】:

您将CustomerMenu()EmployeeMenu() 实现为普通函数,而不是类成员。实施应该是;

int customer::CustomerMenu()
{
...

int employee::EmployeeMenu()
{
...

【讨论】:

    【解决方案2】:

    您的成员函数实现需要正确定义。例如:

    int CustomerMenu()
    

    应该是:

    int  customer::CustomerMenu(void)
    

    等等。

    【讨论】:

      【解决方案3】:
      if(main = 1)
      {   //^^should be ==, same as the one below
          c.EmployeeMenu();
      }
      else if(main = 2)
      {
          b.CustomerMenu();
      }
      

      成员函数应使用范围解析运算符定义:

      int CustomerMenu()
      

      应该是:

      int Customer::ustomerMenu()
      

      小点:

      class employee:store
      

      这里你用private inheritance,你真的需要考虑是否需要它。

      【讨论】:

      • (OP是新手。显然他不需要需要私有继承。)语法应该是class employee : public store。但听起来employee 不太可能继承自store
      • @Elazar 我完全同意你的看法。
      • 感谢两位的意见。正如 Elazar 所说,我是一个初学者。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多