compile problem KHotKeys (KDE_3_2_BRANCH)

Thiago Macieira thiago.macieira at kdemail.net
Sat Apr 17 01:34:54 BST 2004


Jeroen Wijnhout wrote:
> ../../../../../../../src/kde/3_2/kdebase/khotkeys/shared/conditions.h
>:89: sorry,
>   not implemented: adjusting pointers for covariant returns

This is wrong. KDE isn't allowed to use covariant returns because some 
compilers (notably g++) can't handle it.

Therefore, one of the three options:
1) there is a covariant return in that file/line. It should be 
removed/rewritten
2) g++ (yours or everyone's) is misinterpreting a normal situation
or
3) something in your source code is causing a covariant return that 
would not otherwise exist.

The most probable option is #3. Can you check if you get the problem 
with clean sources? Include kdelibs in your cleaning, please.

Here follows an explanation of what a covariant return is (skip if you 
know already):

in C++, you're allowed to do this:
class Base { /* ... whatever ... */ };
class Derived: public Base { /* ... whatever ... */ };

class MyBase
{
	virtual Base* method();
};

class MyDerived: public MyBase
{
	virtual MyDerived* method();
};
[note: MyBase and Base could be the same class, as could MyDerived and 
Derived]

in other words: you're allowed to change a virtual function's return 
type to a class that is derived from the parent's return type. This 
works, even on g++.

What doesn't work is if the above example had:
class Derived: public OtherBase, public Base { /* ... whatever ... */ };

that is, when the derived class to which you're changing the return type 
does not have the base class as its first element.

You could solve the problem by writing the classes like this:
class MyBase
{
protected:
	virtual Base* internalMethod();

public:
	inline Base* method() { return internalMethod(); }
};

class MyDerived: public MyBase
{
protected:
	virtual Base* internalMethod();

public:
	inline Derived* method() 
		{ return static_cast<Derived*>(internalMethod()); }
};

of course, you must guarantee that any further overrides also return an 
object of type Derived or one descended from it.

-- 
  Thiago Macieira  -  Registered Linux user #65028
   thiago (AT) macieira (DOT) info
    ICQ UIN: 1967141   PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20040416/ca0e605f/attachment.sig>


More information about the kde-core-devel mailing list