[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: Generic C++ question (dynamic type)
From: Mark Deneen <deneen () bucknell ! edu>
Date: 2001-02-23 1:59:40
[Download RAW message or body]
I've never done this, but if I remember correctly you can overload the new
operator..
Either way, it looks ugly. :-)
-M
On Thursday 22 February 2001 08:37 pm, Kurt Granroth wrote:
> I have a non-KDE specific C++ question that I think I know the answer
> to... but since there are so many C++ gurus here, I thought I'd ask
> just in case.
>
> I want to create a class that chooses it's type at run-time. The
> basic (non-working) code would look something like this:
>
> class DynamicClass
> {
> public:
> DynamicClass()
> {
> this = new ParentClass();
> }
> };
>
> 'this' can't be used as an lvalue so that doesn't work. But is there
> a way to do that anyway?
>
> FWIW, I know this works but would prefer a non-factory way of doing
> this:
>
> class DynamicClass
> {
> public:
> static Class* init()
> {
> return new ParentClass();
> }
> }
>
> Any clues?
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic