Im trying to detect if the pointers are bad.
But for some reason the func is always called.
I expected it to return as soon as it found the 1st bad pointer, but it keeps calling each function
template<typename T>
inline bool IsValid(T dwAddress) {
return (dwAddress && HIWORD(dwAddress) != 0) ? true : false;
}
#define CHECK_BAD_PTR(x) if(!IsValid(x)) return nullptr
class A{
public:
A() {}
void func(int i){
Sleep(10000);
i += 10;
}
};
class B{
public:
B() {}
inline A* getA() { CHECK_BAD_PTR(this); return a; }
private:
A* a;
};
class C {
public:
inline B* getB() { CHECK_BAD_PTR(this); return b; }
private:
B* b;
};
class D{
public:
D() {}
inline C* getC() { CHECK_BAD_PTR(this); return c; }
private:
C* c;
};
D d;
d.getC()->getB()->getA()->func(10);
Aucun commentaire:
Enregistrer un commentaire