你能帮助解决这个错误吗?(g++原型与类中的任何原型都不匹配)
Can you help resolve this error? (g++ prototype does not match any in class)
以下是编译器输出:
[brian@brian-arch-laptop Lab1]$ g++ -g -Wall -std=c++11 objectIO.cpp main.cpp -o main
objectIO.cpp:33:14: error: prototype for ‘std::vector<Type> objectIO<Type>::loadObjects(Type, std::string, unsigned int, unsigned int)’ does not match any in class ‘objectIO<Type>’
vector<Type> objectIO<Type>::loadObjects(Type dummyObject,
^
objectIO.h:14:23: error: candidate is: static std::vector<Type> objectIO<Type>::loadObjects(std::string, unsigned int, unsigned int)
static vector<Type> loadObjects(Type dummyObject, string fileName, unsigned numObjects,unsigned numLinesPerObject);
^
从我的研究中,我发现这种错误通常发生在一个人声明了一个函数时,但当他们定义它时,它有不同数量的参数或不同类型的参数。我还发现,当使用"const"声明函数,但在定义函数时却未能使用"const"时,通常会发生此错误。
这两种情况都不符合我的情况。我有匹配的光圈,我不会让我的函数保持不变。以下是我的来源:的有问题的行
来自我的源文件(.cpp):
template <class Type>
vector<Type> objectIO<Type>::loadObjects(Type dummyObject,
string filename,
unsigned numObjects,
unsigned numLinesPerObject){/*functionality here*/}
从我的头文件(.h):
template <class Type>
class objectIO{
public:
static vector<Type> loadObjects(Type dummyObject, string fileName,
unsigned numObjects,
unsigned numLinesPerObject);
}
模板类的所有定义都应放在一个头文件中。
您的代码在类的右大括号后缺少分号:
template <class Type>
class objectIO{
public:
static vector<Type> loadObjects(Type dummyObject, string fileName,
unsigned numObjects,
unsigned numLinesPerObject);
} /* <-- RIGHT HERE */
这通常会打乱源代码中接下来出现的内容,有时还会出现一条非常错误的错误消息。
相关文章:
- 函数向量_指针有不同的原型,我可以构建一个吗
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 如何在不产生任何垃圾的情况下获得C中的像素
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- 错误:'EM::EM(...)' 的原型与类 'EM' 中的任何原型都不匹配
- 错误:'void TNode::inititTree(TNode*)' 的原型与类 'TNode' 中的任何原型都不匹配
- 错误:原型与类中的任何原型都不匹配
- "...."的原型与类中的任何"..."都不匹配
- C++ 2D 阵列...迷失在原型和电话上,在任何地方都看不到这个
- 你能帮助解决这个错误吗?(g++原型与类中的任何原型都不匹配)
- 函数的原型与类C++中的任何原型都不匹配
- 错误:类的原型与任何类 - 继承都不匹配
- 错误:“XXX”的原型与类“YYY”中的任何原型都不匹配
- 错误:的原型与类中的任何原型都不匹配
- XXX的原型::XXX与类XXX中的任何一个都不匹配
- 为什么即使没有任何类声明也需要原型
- 错误原型与类中的任何错误都不匹配
- 'Figure::Figure()'的原型与类中的任何'Figure'都不匹配
- 如何声明带有void *指针的c++原型,以便它可以接受任何指针类型