DRAFT document on coding conventions in kde libraries
Leo Savernik
l.savernik at aon.at
Tue Mar 7 19:51:46 GMT 2006
Am Dienstag, 7. März 2006 09:39 schrieb Thiago Macieira:
[...]
> No, I meant complex covariant return values:
>
> struct A {
> int i;
> virtual ~A();
> virtual A *f() { return new A(); }
> };
>
> struct A2 {
> int j;
> virtual ~A2();
> };
>
> struct B: public A2, public A
> {
> virtual B* f() { return new B(); }
> };
>
> gcc 2.95 can't compile this. If you do:
> B *b = new B;
> A *a = b;
>
> Then a == b, but not in value (the pointer values differ).
Augmenting the snippet so that it builds:
struct A {
int i;
virtual ~A() {}
virtual A *f() { return new A(); }
};
struct A2 {
int j;
virtual ~A2() {}
};
struct B: public A2, public A
{
virtual B* f() { return new B(); }
};
#include <stdio.h>
int main() {
B *b = new B;
A *a = b;
printf("a: %p b: %p a==b: %d\n", a, b, a == b);
}
Compiled with gcc-2.95.2 (yes, really old version!) results in:
a: 0x8049fb8 b: 0x8049fb0 a==b: 1
So I can't follow your concern. Whatever, msvc6 doesn't even compile this.
mfg
Leo
More information about the kde-core-devel
mailing list