?
=?ISO-8859-2?Q?=AEeljko_Kne=BEevi=E6?=
Hi,
Given the following code snippet:
======================================================
#include <iostream>
class base {
public:
void f() { std::cout<< "void base::f();" << std::endl; }
};
class derived: public base {
public:
void f() { std::cout << "void derived::f();" << std::endl; }
};
int main() {
base *b = new base;
static_cast<derived*>(b)->f();
return EXIT_SUCCESS;
}
======================================================
The output is: void derived::f();
I'd like someone to confirm me that the output should be treated as
unpredictable because of the second line in main(). I'm casting the base
class into the derived one and there is no guarantee this will work. Am
I mistaken?
®eljko Kne¾eviæ
Given the following code snippet:
======================================================
#include <iostream>
class base {
public:
void f() { std::cout<< "void base::f();" << std::endl; }
};
class derived: public base {
public:
void f() { std::cout << "void derived::f();" << std::endl; }
};
int main() {
base *b = new base;
static_cast<derived*>(b)->f();
return EXIT_SUCCESS;
}
======================================================
The output is: void derived::f();
I'd like someone to confirm me that the output should be treated as
unpredictable because of the second line in main(). I'm casting the base
class into the derived one and there is no guarantee this will work. Am
I mistaken?
®eljko Kne¾eviæ