| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
hi,
I get segmentation fault when returning from member functions. In member function i just change the value of a class variable and come back to the calling function. When i debug the code in the gdb, the this pointer in the calling function is null after i execute the called function and come back. How do i fix this problem??? regards bbr |
|
#2
|
|||
|
|||
|
If the 'this' pointer is NULL it means the class hasn't been instantiated. This is commonly caused by having a pointer to your class and not using new to instantiate it but the function is still available in memory so can be called.
-KM- |
|
#3
|
|||
|
|||
|
hi
the code is as below class a { public: int status; void mfunc1(); void mfunc2(); } void a::mfunc1() { status=true; } void a::mfunc2() { mfunc1(); if(status==true) <....................................... after it executes mfunc1 ; status become inaccessible and i get segmentation fault /......why? { .... .................... } } main() { a *ptr; ptr=new a(); ptr->mfunc2; } |
|
#4
|
|||
|
|||
|
public int: status
i'm not that well versed with c/c++...
i'd just like to ask why you declared status as 'int' if it would be used as a 'boolean'? just curious... ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > this pointer becomes NULL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|