我在从另一个类调用主函数时遇到问题
I'm having trouble calling a function in my main from another class
我有一个主类,我试图在其中调用一个函数来创建菜单,但我不断收到此错误:
错误 LNK2019:函数 _main 中引用的未解析外部符号"public: static int __cdecl Controller::menu(void)"(?menu@Controller@@SAHXZ
)
这是我的主要课程。
#include "Main.h"
using namespace std;
int main ()
{
Control:: menu();
return 0;
}
这是主。
#pragma once
#include "Control.h"
class Main:
{
public:
Main(void);
~Main(void);
int main();
};
控制.h:
#pragma once
#include <iostream>
class Control
{
public:
Control(void);
~Control(void);
static int menu ();
};
最后是控制 cpp 文件:
#include "Control.h"
using namespace std;
static int menu ()
{
bunch of menu code
return 0;
}
我认为这很简单,但我就是想不通。我尝试删除静态并将函数更改为空函数,但都没有奏效。
static int menu ()
{
bunch of menu code
return 0;
}
应该是
int Control::menu ()
{
bunch of menu code
return 0;
}
这是定义成员的正确方法。
静态函数及其原型应该是这样的。
int Control :: menu()
{
//bunch of menu code
return 0 ;
}
在另一个文件中实现类时,还必须将类名与范围解析运算符一起使用。
您在类 Main
的末尾还有一个额外的冒号,从而导致语法错误。
相关文章:
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- 我在 C++ 代码中遇到错误警告:控制到达非空函数 [-Wreturn 类型] 的末尾
- 我在C++中使用 getline() 函数时遇到问题
- 存储另一个函数返回的布尔数组时遇到问题
- 我在解决此错误时遇到问题.我正在努力在主函数中传递数组
- Winsock2:当我尝试发送带有空格的字符串时,该函数在遇到空格时似乎停止发送
- 将结构传递给函数时遇到问题
- 我不明白尝试使用字符串作为函数参数时遇到的错误
- 字数统计函数在将单词添加到一组唯一单词时遇到问题
- 尝试通过多个函数移动数组,但遇到了我不知道如何修复的错误
- 我在生成返回为数不多的模板化参数之一cpp的函数时遇到问题
- 学习C++并在早期示例中遇到错误(在非静态数据成员之前需要构造函数)
- 我在使用字符的函数时遇到了一些问题
- 返回带有另一个类的数据成员的构造函数?遇到转换错误?
- 我在理解 AVX 随机内部函数如何为 8 位时遇到一些问题
- 在使用 std::sort() 和 lambda 函数按属性对 ADT 的向量进行排序时遇到问题
- 在检查传递函数标识符时是否获得模板参数时遇到问题
- 调用基构造函数时遇到问题 - 获取读取访问冲突
- 在使用结构体和用函数填充其变量(使用指针)时遇到问题
- 遇到错误试图在功能型参数中使用void函数的错误