B
Ben Thomas
Hi,
Is this code okay and compliant with the standard. As far as I
understand it is correct but I just want to make sure.
Thank you,
Ben.
----
#include <iostream>
using namespace std;
class Base {
public:
typedef void (Base::*PMethod)(void);
void Invoke (PMethod p) {(this->*p)();}
};
class Derived : public Base {
public:
void Method (void) {cout << "Hello World" << endl;}
};
int main (void) {
Derived x;
// *** Is the static_cast correct here ? Or could this leads
// to undefined behavior on some platform / compiler ?
x.Invoke(static_cast<Base:Method>(&Derived::Method));
return 0;
}
Is this code okay and compliant with the standard. As far as I
understand it is correct but I just want to make sure.
Thank you,
Ben.
----
#include <iostream>
using namespace std;
class Base {
public:
typedef void (Base::*PMethod)(void);
void Invoke (PMethod p) {(this->*p)();}
};
class Derived : public Base {
public:
void Method (void) {cout << "Hello World" << endl;}
};
int main (void) {
Derived x;
// *** Is the static_cast correct here ? Or could this leads
// to undefined behavior on some platform / compiler ?
x.Invoke(static_cast<Base:Method>(&Derived::Method));
return 0;
}