Tuesday, 15 May 2012

c++ - Extending enumerated properties in derived class -



c++ - Extending enumerated properties in derived class -

i'm looking way utilize enumerated properties can extended in derived classes new properties can introduced.

using enum fails due type mismatch, , other thought can think of define static const int's in header files.

is there improve approach in c++?

a scenario able utilize like:

#include <cstdio> class { public: typedef enum { prop1 = 10, prop2, prop_last, } property; void setprop (property p) { = p; } property getprop() { homecoming a; } private: property a; }; class d1 : public { public: typedef enum { prop3, prop4, } property; }; class d2 : public { public: typedef enum { prop5, prop6, } property; }; int main() { d1 d1; d2 d2; d1.setprop(a::prop1); printf ("%d\n", d1.getprop()); d1.setprop(d1::prop3); // compilation error: wrong type printf ("%d\n", d1.getprop()); homecoming 0; }

c++

No comments:

Post a Comment