gpt4 book ai didi

c++ - 你能帮忙解决这个错误吗? (g++ 原型(prototype)与类中的任何一个都不匹配)

转载 作者:太空宇宙 更新时间:2023-11-04 11:41:28 25 4
gpt4 key购买 nike

这是编译器的输出:

[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”时,通常会发生此错误。

这些情况都不符合我的情况。我有匹配的参数,但我没有让我的函数保持不变。以下是我的来源中有问题的几行:

来 self 的源 (.cpp) 文件:

template <class Type>
vector<Type> objectIO<Type>::loadObjects(Type dummyObject,
string filename,
unsigned numObjects,
unsigned numLinesPerObject){/*functionality here*/}

来 self 的头文件 (.h):

template <class Type>
class objectIO{
public:
static vector<Type> loadObjects(Type dummyObject, string fileName,
unsigned numObjects,
unsigned numLinesPerObject);

}

最佳答案

一个模板类的所有定义都应该放在一个头文件中。

关于c++ - 你能帮忙解决这个错误吗? (g++ 原型(prototype)与类中的任何一个都不匹配),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21210424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com