C++成员函数未声明错误时(当它看起来是错误时)
C++ member function not declared error, when it appears to be
我收到错误:
CS163hw1.cpp:41:24:错误:在类"菜单类型"中没有声明"int menutype::run_prog()"成员函数
和
主.cpp:18:7: 错误:"结构菜单类型"没有名为"run_prog"的成员
尝试使用关联的代码(跨越 appriprait .cpp 和 .h 文件)编译我的程序时:
int main(int argc, char ** argv){
...
menu.run_prog();
...
class menutype{
public:
menutype(int);
int display();
int run_prog();
private:
extras list;
person menup;
};
int menutype::run_prog(){
bool exit = false;
int input;
while(!exit){
input = 0;
while(input < 1 || input > 4)
input = display();
switch(input){
case 1 :
break;
case 2 :
break;
case 3 :
break;
case 4 : exit = true;
break;
default :
break;
}
}
}
我不知道为什么会这样,有什么猜测吗?
你需要
在main()上面声明class menutype
。 更好的方法是将类移动到它自己的专用文件中,称为menutype.cpp并将标头包含在main的源文件中。 正如您所描述的,编译器还不知道菜单类型,因为它从文件顶部解析源文件。
相关文章:
- std::vector的包装器,使数组的结构看起来像结构的数组
- 看起来is_nothrow_constructible_v()在MSVC中被破坏了,我错了吗
- 学习多线程C++:添加线程不会使执行速度更快,即使它看起来应该
- 尽管一切看起来都很好,但值不会交换
- 自制的上衣:看起来一样,但不完全相同
- 如何使它看起来像正在下的雪
- 如何用逗号分隔输出?如何改进此代码以使其看起来更体面?
- 我的代码看起来不错,但某些输入会导致不需要的输出
- 为什么这个结构的大小是 40,而它看起来应该是 12/24?
- 我需要将阵列样式的邻接矩阵转换为矢量样式(以使其看起来更好)
- 结构化绑定:当某些内容看起来像引用并且行为类似于引用,但它不是引用时
- 如何使QTextEdit看起来被禁用
- 看起来如此主要的错误.cpp:(.text.startup+0xd6):未定义对"vtable for Counter"的引用?
- C++成员函数未声明错误时(当它看起来是错误时)
- C++ 为什么当错误看起来 100% 匹配时会出现错误"no matching function"?
- 为什么在使用初始化语法时不调用转换运算符,为什么 clang 错误消息看起来是错误的
- 使用 c++,为什么我知道它不是时会收到错误消息“字符串下标超出范围”?或者至少看起来是这样
- SSSE3 的 strncpy 段错误 尽管所有参数看起来都正确
- 看起来非常好的C++代码会导致错误
- LNK2005错误.看起来一个文件被包含了两次