我有一个很奇怪的问题...首先,这是我类(class)的文件:
显示.h:
#ifndef SHOW
#define SHOW
#include <iostream>
#include <string>
#include <string.h>
class Show
{
private:
std::string m_time;
int m_serial
public:
Show(const std::string &time, const int &serial);
~Show();
};
#endif
显示.c:
#include "Show.h"
Show::Show(const std::string &time,const int &serial)
{
}
正如您可能看到的那样,我只写了构造函数的声明,当 visual studio 在 Show.c 文件中的第二个“Show”单词下划线时,告诉我:
“void Show::Show(const std::string &time,const int &serial)
显示::显示()
显示::显示(const Show &)
错误:没有重载函数“Show::Show”的实例匹配特定类型”
当我将鼠标光标放在 Show.h 文件中的构造函数上时,它看起来好像该函数不存在...我以前用 C++ 编写过一些类,这是第一次这发生在我身上......请帮忙:(
最佳答案
您忘记将 ;
放在 m_serial
字段变量之后。我相信这是你遇到问题的原因。不幸的是,许多编译器没有给出此类问题的确切原因,因此您必须注意语法规则。
关于c++ - 构造函数中的错误 : no instance of overloaded function, (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15850084/