Problem with explicit copy ctor

Stromek stromek at realtime.sk
Mon Feb 26 13:25:06 CET 2007


On Fri, Feb 23, 2007 at 08:19:50PM +0100, Christian Ehrlicher wrote:
> Stromek schrieb:
> <snip>
> >Btw. if we are talking about this copy constructor issue I have a 
> >question. I am not a developer of kde stuff and I don't understand its 
> >specifics, particulary this KConfig class, however, what it is good for to 
> >have a copy constructor in the child if the parent declared it private? 
> >For me, that means you "cannot make a copy" of the object because you 
> >cannot copy attributes of the parent. In reality, you can make it but it 
> >won't be a copy because the attributes declared in the parent will be 
> >default.
> >
> for now a solution is to add an empty detach to class KSharedConfigPtr
> 
>     void attach() {qWarning("KSharedConfigPtr::attach() was called");}
> 
> This should solve the problems.

did you mean

1. "add an empty detach" -> add an empty attach,
2. or "void attach()" -> void KSharedConfigPtr::detach()?

Anyway, first, adding "void KSharedConfigPtr::detach()" does not help. Second, KSharedConfigPtr already contains attach method. Commenting its body out does not help. The same error shown below is returned by the compiler in either of the situation.

Adding KSharedConfigPtr::detach() method does not help, in my opinion, because of

    class KSharedConfigPtr : public KSharedPtr<KSharedConfig>

and then KSharedPtr<KSharedConfig> generates the error. KSharedPtr contains detach method which uses copy ctor of KSharedConfig which is declared private in KConfig. So the solution could be, modify KSharePtr::detach(),

template <class T>
Q_INLINE_TEMPLATE void KSharedPtr<T>::detach()
{
	qWarning( "KSharedPtr::detach was called" );
/*
    if (d && d->ref>1) {
        attach(new T(*d));
    }
*/
}

N:\incoming\kde\kdelibs\KDE\kdelibs-build>devenv /build Release /project INSTALL
 /useenv kdelibs.sln

Microsoft (R) Development Environment  Version 7.10.3077.
Copyright (C) Microsoft Corp 1984-2001. All rights reserved.
------ Build started: Project: kdecore, Configuration: Release Win32 ------

Compiling...
ktoolinvocation_win.cpp
N:\incoming\kde\kdelibs\KDE\kdelibs\kdecore\util\ksharedptr.h(224) : error C2558
: class 'KSharedConfig' : no copy constructor available or copy constructor is d
eclared 'explicit'
        n:\Qt\4.2\include\QtCore\../../src\corelib\tools\qlist.h(87) : while com
piling class-template member function 'void KSharedPtr<T>::detach(void)'
        with
        [
            T=KSharedConfig
        ]
        N:\incoming\kde\kdelibs\KDE\kdelibs\kdecore\config\ksharedconfig.h(81) :
 see reference to class template instantiation 'KSharedPtr<T>' being compiled
        with
        [
            T=KSharedConfig
        ]

-- 
Stromek



More information about the Kde-windows mailing list