D
duey
Can anyone explain how this works?
class Test
{
public:
Test() {}
int x;
std::wstring id;
void func() { std::cout << "Calling func" << std::endl; }
};
int main()
{
int junk = 0x6554433;
void* ptr = (void*)junk;
Test* tt = dynamic_cast<Test*>( (Test*)ptr);
if ( tt == NULL )
{
std::cout << "Invalid Test pointer" << std::endl;
}
else
{
std::cout << "Valid Test pointer" << std::endl;
tt->func();
}
return 0;
}
The output is:
Valid Test pointer
Calling func
I would have expected this code to return an invalid pointer.
Thanks,
Kevin
class Test
{
public:
Test() {}
int x;
std::wstring id;
void func() { std::cout << "Calling func" << std::endl; }
};
int main()
{
int junk = 0x6554433;
void* ptr = (void*)junk;
Test* tt = dynamic_cast<Test*>( (Test*)ptr);
if ( tt == NULL )
{
std::cout << "Invalid Test pointer" << std::endl;
}
else
{
std::cout << "Valid Test pointer" << std::endl;
tt->func();
}
return 0;
}
The output is:
Valid Test pointer
Calling func
I would have expected this code to return an invalid pointer.
Thanks,
Kevin