链表显示;缺少..但事实并非如此
Linked List says ; is missing...but its not
我正在尝试制作一个简单的链表。一切都很顺利,然后突然发生了一场错误大屠杀。我不知道我改变了什么来破坏我的代码。这是我的文件,得到了一些错误:
#pragma once
#include <string>
#include "Node.h"
class LinkedList
{
private:
Node *head;
public:
LinkedList();
~LinkedList();
void AddNode(int);
string GetList(); //missing ';' before identifier 'GetList'
bool Contains(int);
void Remove(int);
};
它声称我在string GetList();
上方的行上缺少一个分号,或者看起来。。。但显然我不是。确切的错误是:
Error 1 error C2146: syntax error : missing ';' before identifier 'GetList' c:...linkedlist.h 15 1 ProjectName
这条线上的另一个错误是:
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:...linkedlist.h 15 1 ProjectName
但它被标识为字符串返回类型。
在LinkedList.cpp中,这是GetList()方法:
string LinkedList::GetList(){
string list;
Node *currentNode = head;
while (currentNode->next_node){
currentNode = currentNode->next_node;
list += currentNode->get_value() + " ";
}
return list;
}
这一切看起来都很好,但在方法标题中,我得到了以下2个错误:
Error 4 error C2556: 'std::string LinkedList::GetList(void)' : overloaded function differs only by return type from 'int LinkedList::GetList(void)' c:...linkedlist.cpp 28 1 ProjectName
错误5错误C2371:"LinkedList::GetList":重新定义;不同的基本类型c:。。。\linkedlist.cpp 28 1项目名称
我甚至创建了一个新项目,复制并粘贴回我所有的文件,但没有效果。我之前已经在这个程序中成功地运行了GetList()。
有人知道这里到底发生了什么吗?我的IDE在骗我!(Visual Studio社区2013更新4)
您在LinkedList.cpp中的某个位置有using namespace std;
,但在LinkedList.h中没有。这就是为什么在类定义中,当您编写string
时,它不知道您指的是std::string
。
我建议停止使用using namespace std;
以避免此类问题。
使用std::string
,而不仅仅是string
。
相关文章:
- 伪造事实↔false
- 为什么右值不能绑定到非常量左值引用,除了写入临时无效的事实?
- 如何在CLIPS中优化不同模板事实之间的模式匹配
- 无法在剪辑嵌入式应用程序中断言事实
- 生成(并非如此)出现特定字符串的随机字符串
- 链表显示;缺少..但事实并非如此
- C++ 通过引用传递单个元素数组 - 这是事实吗?
- C++ 矢量下标超出范围(但事实并非如此)
- 视觉C++将其视为常量,而事实并非如此
- C++前缀增量运算符返回左值这一事实的实际用法
- 此代码看起来像是删除了此对象,但事实并非如此
- C++ "warning: returning reference to temporary " - 但事实并非如此
- MSG类型背后的事实
- Json chuck事实解析
- 我的类主要是容器的前端,我应该公开这个事实吗
- 有什么方法可以解决 c++ 不支持运行时模板的事实吗?
- 利用vector的元素存储在堆中的事实
- 转化会失去限定符,但实际上并非如此
- 为什么is_constructible声称某物是可构造的,而实际上并非如此?
- 从 C/C++ 调用 Prolog 时将事实传达给 Prolog(不使用断言)