Click here to Skip to main content
16,011,538 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCImageList when .draw -> no more transparent Pin
karhong8-Jan-09 17:15
karhong8-Jan-09 17:15 
AnswerRe: CImageList when .draw -> no more transparent Pin
Naveen8-Jan-09 18:29
Naveen8-Jan-09 18:29 
GeneralRe: CImageList when .draw -> no more transparent Pin
karhong8-Jan-09 18:42
karhong8-Jan-09 18:42 
GeneralRe: CImageList when .draw -> no more transparent Pin
Iain Clarke, Warrior Programmer9-Jan-09 0:28
Iain Clarke, Warrior Programmer9-Jan-09 0:28 
QuestionPreventing / Checking null 'this' pointer adjustment w/ Multiple Inheritance Pin
D. Miller8-Jan-09 13:18
D. Miller8-Jan-09 13:18 
AnswerRe: Preventing / Checking null 'this' pointer adjustment w/ Multiple Inheritance Pin
Stuart Dootson8-Jan-09 13:39
professionalStuart Dootson8-Jan-09 13:39 
GeneralRe: Preventing / Checking null 'this' pointer adjustment w/ Multiple Inheritance Pin
D. Miller9-Jan-09 1:47
D. Miller9-Jan-09 1:47 
GeneralRe: Preventing / Checking null 'this' pointer adjustment w/ Multiple Inheritance Pin
Stuart Dootson9-Jan-09 2:20
professionalStuart Dootson9-Jan-09 2:20 
How about dynamic_cast?

if (dynamic_cast<basetype*>(SomePointer)) { /* we know that SomePointer is castable to BaseType */ }


Consider this code:

#include <iostream>

class Base1
{
public:
   virtual DoSomething1() const { std::cout << "Base1::DoSomething1 @ " << (int*)(this) << "\n"; }
};

class Base2
{
public:
   virtual DoSomething2() const { std::cout << "Base2::DoSomething2 @ " << (int*)(this) << "\n"; }
};

class Base3
{
public:
   virtual DoSomething3() const { std::cout << "Base3::DoSomething3 @ " << (int*)(this) << "\n"; }
};

class Derived : public Base1, public Base2
{
public:
   virtual DoSomething1() const { std::cout << "Derived::DoSomething1 @ " << (int*)(this) << "\n"; }
   virtual DoSomething2() const { std::cout << "Derived::DoSomething2 @ " << (int*)(this) << "\n"; }
};

int main(int, char**)
{
   Derived d;
   
   std::cout << "d @ " << (int*)(&d) << std::endl;
   
   std::cout << "dynamic_cast<Base1*>(&d) == " << dynamic_cast<Base1*>(&d) << std::endl;
   std::cout << "dynamic_cast<Base2*>(&d) == " << dynamic_cast<Base2*>(&d) << std::endl;
   std::cout << "dynamic_cast<Base3*>(&d) == " << dynamic_cast<Base3*>(&d) << std::endl;
   std::cout << "dynamic_cast<Base1*>(0) == " << dynamic_cast<Base1*>((Derived*)0) << std::endl;
   std::cout << "dynamic_cast<Base2*>(0) == " << dynamic_cast<Base2*>((Derived*)0) << std::endl;
   std::cout << "dynamic_cast<Base3*>(0) == " << dynamic_cast<Base3*>((Derived*)0) << std::endl;
   return 0;
}


We get this output:

d @ 0012FEDC
dynamic_cast<Base1*>(&d) == 0012FEDC
dynamic_cast<Base2*>(&d) == 0012FEE0
dynamic_cast<Base3*>(&d) == 00000000
dynamic_cast<Base1*>(0) == 00000000
dynamic_cast<Base2*>(0) == 00000000
dynamic_cast<Base3*>(0) == 00000000


So dynamic_cast indicates inheritance relationships with a NULL and will also detect null 'this' pointers properly.
QuestionOverflowing the Windows’s message Queue Pin
BobInNJ8-Jan-09 7:21
BobInNJ8-Jan-09 7:21 
GeneralRe: Overflowing the Windows’s message Queue Pin
Luc Pattyn8-Jan-09 7:51
sitebuilderLuc Pattyn8-Jan-09 7:51 
GeneralRe: Overflowing the Windows’s message Queue Pin
BobInNJ8-Jan-09 10:06
BobInNJ8-Jan-09 10:06 
AnswerRe: Overflowing the Windows’s message Queue Pin
Code-o-mat8-Jan-09 8:56
Code-o-mat8-Jan-09 8:56 
GeneralRe: Overflowing the Windows’s message Queue Pin
BobInNJ8-Jan-09 10:10
BobInNJ8-Jan-09 10:10 
GeneralRe: Overflowing the Windows’s message Queue Pin
David Crow8-Jan-09 10:15
David Crow8-Jan-09 10:15 
GeneralRe: Overflowing the Windows’s message Queue Pin
Code-o-mat8-Jan-09 10:31
Code-o-mat8-Jan-09 10:31 
GeneralRe: Overflowing the Windows’s message Queue Pin
BobInNJ8-Jan-09 11:18
BobInNJ8-Jan-09 11:18 
GeneralRe: Overflowing the Windows’s message Queue Pin
Code-o-mat8-Jan-09 21:45
Code-o-mat8-Jan-09 21:45 
GeneralRe: Overflowing the Windows’s message Queue Pin
David Crow9-Jan-09 3:32
David Crow9-Jan-09 3:32 
GeneralRe: Overflowing the Windows’s message Queue Pin
BobInNJ9-Jan-09 6:20
BobInNJ9-Jan-09 6:20 
GeneralRe: Overflowing the Windows’s message Queue Pin
BobInNJ8-Jan-09 12:02
BobInNJ8-Jan-09 12:02 
AnswerRe: Overflowing the Windows’s message Queue Pin
Roger Stoltz8-Jan-09 12:05
Roger Stoltz8-Jan-09 12:05 
GeneralRe: Overflowing the Windows’s message Queue Pin
Code-o-mat8-Jan-09 21:38
Code-o-mat8-Jan-09 21:38 
GeneralRe: Overflowing the Windows’s message Queue Pin
BobInNJ9-Jan-09 8:02
BobInNJ9-Jan-09 8:02 
AnswerRe: Overflowing the Windows’s message Queue Pin
David Crow8-Jan-09 9:08
David Crow8-Jan-09 9:08 
GeneralRe: Overflowing the Windows’s message Queue Pin
BobInNJ8-Jan-09 10:03
BobInNJ8-Jan-09 10:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.