[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Pimpl idiom
From: Peter_Kümmel <syntheticpp () gmx ! net>
Date: 2006-03-04 9:25:05
Message-ID: 44095CF1.4000402 () gmx ! net
[Download RAW message or body]
Marc Mutz wrote:
>> It is pure C++ and needs no macros or static variables.
>
> Yes, and since it uses no macros, it doesn't support the
> Derived::Private : public Base::Private
> optimization found in Qt4...
I've written a small test program
to see the problem you are talking about:
#include "KImpl.h"
#include <iostream>
namespace Private
{
int count = 1;
struct BImpl
{
BImpl()
{
std::cout << "BImpl created, " <<count<< "\n";
count++;
}
void foo(){std::cout<<"BImpl::foo()\n";}
};
struct CImpl : BImpl
{
CImpl() : BImpl()
{
std::cout<<"CImpl created \n";
}
void foo(){std::cout<<"CImpl::foo()\n";}
};
}
struct B
{
B()
{
d->foo();
}
KPimpl<Private::BImpl> d;
};
struct C : B
{
C() : B()
{
d->foo();
}
KPimpl<Private::CImpl> d;
};
int main()
{
C c;
system("pause");
return 0;
}
And the output is:
BImpl created, 1
BImpl::foo()
BImpl created, 2
CImpl created
CImpl::foo()
The "only" problem I see is the multiple creation of BImpl,
am I right?
Or are there more problems?
Maybe there is a macro-free way to handle this problem.
Peter
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic