Click here to Skip to main content
15,921,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have declared a class node. When i am declaring a global variable head i am getting an error but when i am declaring it in main() i compile successfully.
CSS
class Node
{
public:
    int data;
    Node* next;
};
Node *head;
head=NULL;

int main()
{

    Node *temp= new Node;
    temp->data=5;
    temp->next=NULL;
    head=temp;
    cout << "head->data= "<<head->data<<" head->next= "<<head->next;

    return 0;
}


error= 'head' does not name a type
Posted

1 solution

C#
Node *head=NULL;


is what you're after

you can only declare or declare_AND_define outside code
 
Share this answer
 
Comments
the_beginner 1-Sep-15 1:03am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900