Consider this example:
#include <iostream>
class myclass
{
public:
void print() { std::cout << "myclass"; }
};
int main()
{
myclass* p = 0x0; // any address
p->print(); // prints "myclass"
}
I didn't call the member function print
through an object of type myclass. Instead I called it from a pointer to a random place in memory. Is this a defined behavior? That is, is the member function guaranteed to be executed before the creation of any object of type myclass
?