A
Alex Vinokur
// Here jack is not instance but pointerBaloff said:Hello
I never got this error before, I would appreciate help. thank you
$ make
g++ -c -o main.o main.cpp
g++ -g -Wall -o proj1 main.o
$ ./proj1
Segmentation fault
******************************code******************************
#include <iostream>
using namespace std;
struct person
{
int year;
};
void set(person* ag, int yr){
ag->year = yr;
}
void get(person* ag){
cout << "my age is "
<< ag->year << " years"
<< endl;
}
int main(){ --------------------
person* jack;
--------------------set(jack, 22);
get(jack);
person jack;
set(&jack, 22);
get(&jack);
}
******************************makefile******************************
OBJS = main.o
CFLAGS = -g -Wall
CFLAGS= -g -Wall
proj1 : $(OBJS)
$(CXX) $(CFLAGS) -o $@ $(OBJS)
clean :
rm -f $(OBJS) proj1
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn