hi
i have a class with a member which is a pointer to an object on the heap.
(the object is created from outside the class and is passed to it as a reference in the constructor).
when i try to access it from void functions, everything is ok.
but when i try to access it from value returning functions, i get a segmentation fault.
(the functions are public members of the class)
is it something i'm missing, or is just impossible? (to access from value returning funcs..)
class candidate{
private:
...
int id;
myClock *clock;
...
public:
candidate (int _id, myClock &_clock ); //constructor
int getID();
void waiting();
};
candidate::candidate
(int _id, myClock &_clock)
{
id = _id;
clock = &_clock;
}
int candidate::getID(){
(*clock).some_method(); // <=this generates segfault
return id;
}
void candidate::waiting(){
(*clock).some_method(); // <===== this doesnt
}
i dont understand why the myClock object is not visible from the getID() method.
thaks!