Node* Insert(Node *head,int data)
{
Node *current=head;
Node *new=(Node *)malloc(size0f(Node));
new->data=data;
while(current->next!=NULL)
{
current=current->next;
}
current->next=new;
new->next=NULL;
return head;
}
错误:
solution.cc: In function 'Node* Insert(Node*, int)':
solution.cc:23:10: error: expected unqualified-id before 'new' Node *new=(Node *)malloc(size0f(Node)); ^
solution.cc:23:10: error: expected initializer before 'new'
solution.cc:24:7: error: expected type-specifier before '->' token new->data=data; ^
solution.cc:29:22: error: expected type-specifier before ';' token current->next=new; ^
solution.cc:30:8: error: expected type-specifier before '->' token new->next=NULL;
答案 0 :(得分:1)
我认为`Node *new=(Node *)malloc(size0f(Node));`
是一个关键字,您尝试将其用作
newNode
及后续代码。
尝试将其替换为类似`Node *newNode=(Node *)malloc(size0f(Node));`
的内容,如下所示
newNode
然后在后续代码中使用new
而不是 class A {
public void say() {
System.out.println("From super");
}
}
class Demo extends A {
@Override
public void say() {
//Check if user have called super.say() or not if not throw a custom exception
super.say();
System.out.println("From Child");
}
public static void main(String[] args) {
Demo d = new Demo();
d.say();
}
}
答案 1 :(得分:0)
我猜@vmachan是对的,你不应该使用new
作为变量名。
此外,我认为您正在寻找sizeof
而不是size0f
?