Re: extending c++ classes and enumerations
alex skrev:
Not sure about extending classes, but enums... Let's add:
enum2.h:
extend enum ThreadState { ANOTHER_STATE };
enum3.h:
extend enum ThreadState { YET_ANOTHER_STATE };
And then the real value of ANOTHER_STATE will depend on the order of
header inclusions :)
No, not really. :-) If enums are defined in polymorphical classes, the
order can be preserved.
// Thread.h
class Thread {
enum ThreadState { ERROR = -1, RUNNING, TERMINATED };
};
// CancelableThread.h
class CancelableThread : public Thread {
extend enum ThreadState { CANCELLED };
};
// Enum2.h
class MyThread1 : public CancelableThread {
extend enum ThreadState { ANOTHER_STATE };
};
// Enum3.h
class MyThread2 : public MyThread1 {
extend enum ThreadState { YET_ANOTHER_STATE };
};
I should be honesty and confess my primary thoughts is about extending
classes. Extending enums just happend to be included in my earlier
message. :-)
Of course, the same undefined situation happens if we allow extending
classes.
// Enum3+extra.h
extend class MyThread2 : public MyThread1 {
extend enum ThreadState { YET_ANOTHER_EXTRA_STATE };
};
....and if friends extend enums
// ThreadManager.h
class ThreadManager {
typedef typename Thread::ThreadState ThreadState;
extend enum ThreadState { SCHEDULED };
};
...and if we use another design pattern
class Thread;
class WorkerThread {
Thread *thread;
typedef typename Thread::ThreadState ThreadState;
extend enum ThreadState { YET_ANOTHER_STATE_AGAIN };
};
However, extending classes feels like the next step in creating
reusable code.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]