Reputation: 35
Hi I'm having a problem with global pointer being underclared in function. Here is my code
#include <iostream>
using namespace std;
void push_l(int n);
struct elem{
int key;
elem *next;
} *left=NULL,*right=NULL;
void push_l(int n){
elem *p=left;
left=new elem;
left->key=n;
left->next=p;
if (right==NULL)right=left;
}
int main(){
push_l(5);
system "pause";
return 0;
}
This is one of the error messages I get - In function void push_l(int) left underclared
Upvotes: 0
Views: 209
Reputation: 1359
This is what you get for using namespace std;
(std
has a left
too). And you don't even need iostream
. The reference to left
is ambiguous.
Do this:
#include <cstdlib>
struct elem{
int key;
elem *next;
} *left=NULL,*right=NULL;
void push_l(int n){
elem *p=left;
left=new elem;
left->key=n;
left->next=p;
if (right==NULL)right=left;
}
int main(){
push_l(5);
std::system("pause");
return 0;
}
Upvotes: 2