-
Linked Lists
I create a linked lists and get three errors:
Code:
Error E2176 C:\linkedlist.cpp 10: Too many types in declaration
Error E2111 C:\linkedlist.cpp 11: Type 'linkedlist' may not be defined here
Error E2034 C:\linkedlist.cpp 27: Cannot convert 'int' to 'linkedlist' in function main()
here is my code:
Code:
#include<iostream>
#include<string>
#include<conio>
using namespace std;
struct linkedlist
{
string key;
linkedlist *next;
}
int main()
{
linkedlist *first = NULL, *second = NULL, *third = NULL, *fourth = NULL;
first = new linkedlist;
first->key = "Hello, ";
second = new linkedlist;
first->next = second;
second->key="my ";
third = new linkedlist;
second->next=third;
third->key="name's";
fourth = new linkedlist;
fourth->key=" Joe!";
fourth->next=NULL;
cout<<first->key<<second->key<<third->key<<fourth->key;
cout.flush();
getch();
return 0;
}
-
Put a semi-colon after the closing brace '}' of your struct.
-
It worked! Stupid me on that structure I didn't put a semicolon.