C++ 为方法提供实现时出现不兼容的声明错误

C++ 为方法提供实现时出现不兼容的声明错误,c++,compiler-errors,C++,Compiler Errors,获取错误: 声明与 LinkedList::toString()常量 我是这样声明函数的: string toString() const; 在定义这一点时,我已经做了: #include "ListInterface.h" #include "node.h" #include <string> template <class ItemType> class LinkedList : public ListInterface&l

获取错误:

声明与 LinkedList::toString()常量

我是这样声明函数的:

string toString() const;
在定义这一点时,我已经做了:

#include "ListInterface.h"
#include "node.h"
#include <string>

template <class ItemType>
class LinkedList : public ListInterface<ItemType>
{
public:
vector<ItemType> toVector() const;
    string toString() const;
}
#包括“ListInterface.h”
#包括“node.h”
#包括
模板
类LinkedList:公共ListInterface
{
公众:
向量toVector()常量;
字符串toString()常量;
}
它们看起来一模一样,我不确定我在这里遗漏了什么

我定义了以下两个类:

#include "LinkedList.h"
#include "node.h"
#include "ListInterface.h"
#include <string>
using namespace std;

template <class ItemType>
class LinkedList : public ListInterface<ItemType>
{
private:
    Node<ItemType> *headPtr;
    int itemCount;
   
public:
    vector<ItemType> toVector() const;
    string toString() const;
};
 
#endif   
  
template <class ItemType>
string LinkedList<ItemType>::toString() const
{
    std::string ListContents;
    Node<ItemType> *curPtr = headPtr;
    int counter = 0;
    while ((curPtr != nullptr) && (counter < itemCount))
    {
        ListContents += (curPtr->getItem());
        curPtr = curPtr->getNext();
        counter++;
    }
    
    return ListContents;
}
#包括“LinkedList.h”
#包括“node.h”
#包括“ListInterface.h”
#包括
使用名称空间std;
模板
类LinkedList:公共ListInterface
{
私人:
节点*headPtr;
整数项计数;
公众:
向量toVector()常量;
字符串toString()常量;
};
#恩迪夫
模板
字符串LinkedList::toString()常量
{
std::字符串列表内容;
节点*curPtr=headPtr;
int计数器=0;
while((curPtr!=nullptr)&&(计数器getItem());
curPtr=curPtr->getNext();
计数器++;
}
返回列表内容;
}

std::string
string
本身不是一个类型。我怀疑
使用了名称空间std此外,在显示的代码中没有
#include
的迹象。我们需要查看您的所有相关代码。我已经更新了代码。我在发帖的时候完全搞糊涂了。
#include
在另一个头文件
ListInterface.h
中,我想现在应该可以了。所以,;你的代码离其他人可以复制的东西还有很长的路要走。。。但是靠近代码块中间的
#endif
看起来特别奇怪。