C++ 关于意外令牌c2760的LinkedList头文件错误
我在试图编译程序时收到一个C2760错误。它来自这段代码。这是一个LinkedList.h文件,可与其他文件一起使用 一切C++ 关于意外令牌c2760的LinkedList头文件错误,c++,visual-studio-2017,C++,Visual Studio 2017,我在试图编译程序时收到一个C2760错误。它来自这段代码。这是一个LinkedList.h文件,可与其他文件一起使用 一切 void Insert(T data) { if (head == nullptr) //If the list is empty { head = new Node<T>(data, nullptr) } //error C2760 Given from this line. Tutor was unable to fix
void Insert(T data)
{
if (head == nullptr) //If the list is empty
{
head = new Node<T>(data, nullptr)
} //error C2760 Given from this line. Tutor was unable to fix
else
{
Node<T> *temp = head
Node<T> *tempT = nullptr
while (temp != nullptr && temp->data <data):
{
tempT = temp
temp = temp->next
}
if (temp == nullptr)
{
tempT->next = new Node<T>(data, nullptr)
}
else if (temp == head)
{
tempT = new Node<T>(data, head)
head = tempT
}
else
{
tempT->next = new Node<T>(data, temp)
}
}
}
void插入(T数据)
{
if(head==nullptr)//如果列表为空
{
head=新节点(数据,空PTR)
}//此行出现错误C2760。导师无法修复
其他的
{
节点*温度=头部
节点*TENT=nullptr
while(temp!=nullptr&&temp->data next
}
if(temp==nullptr)
{
试探->下一步=新节点(数据,空PTR)
}
否则,如果(温度==水头)
{
试探=新节点(数据、头)
头=诱惑
}
其他的
{
试探->下一步=新节点(数据、临时)
}
}
}
陈述
错误C2760语法错误:意外标记“}”,应为“;”
此错误的修复方法语句中缺少分号 即:
head=新节点(数据,空ptr);
您已经错过了几个(9)位置。此外,while循环上的冒号也无效
因此,完全的改变将是:
void Insert(T data)
{
if (head == nullptr) //If the list is empty
{
head = new Node<T>(data, nullptr);
}
else
{
Node<T> *temp = head;
Node<T> *tempT = nullptr;
while (temp != nullptr && temp->data <data)
{
tempT = temp;
temp = temp->next;
}
if (temp == nullptr)
{
tempT->next = new Node<T>(data, nullptr);
}
else if (temp == head)
{
tempT = new Node<T>(data, head);
head = tempT;
}
else
{
tempT->next = new Node<T>(data, temp);
}
}
void插入(T数据)
{
if(head==nullptr)//如果列表为空
{
head=新节点(数据,空PTR);
}
其他的
{
节点*温度=头部;
节点*TELT=nullptr;
while(temp!=nullptr&&temp->data next;
}
if(temp==nullptr)
{
试探->下一步=新节点(数据,空PTR);
}
否则,如果(温度==水头)
{
试探=新节点(数据、头);
头=诱惑;
}
其他的
{
试探->下一步=新节点(数据、临时);
}
}
考虑从C++学习C++。代码中的所有语句在结尾都是“<代码>;”。总是张贴完整的错误信息。在VisualStudio中,可以很容易地从输出选项卡中复制这个词。是的,我指的是Output Tab而不是错误列表。错误列表包含错误消息的简化版本,并且更为不同。我无法复制,因为它被分成了几列。修复后,我收到了相同的错误严重性代码描述项目文件行抑制状态错误C2760语法错误:意外的标记“identifier”,应为行“Node*atter=nullptr”@JobPlumpp引用答案“You have missing in几个地方”,这意味着-您需要以类似的方式在所有缺少分号的行上添加缺少的分号。我已经添加了所有分号,但仍然收到与else if语句相关的错误C2760。感谢您的帮助。您确定拥有所有分号吗?同样,如果没有最小的完整代码,很难知道您是否遗漏了之前还有别的事吗