egcs does not prevent abstract classes creation ????
Khimenko Victor
khim@sch57.msk.ru
Thu Sep 17 11:14:00 GMT 1998
egcs (both 1.0.x & 1.1b) does not prevent creation of abstract classes in
some cases !
Example:
-- cut --
struct A {
virtual void f(void) =0;
};
void A::f(void) { }
main() {
A().f();
}
-- cut --
This program will be compiled just fine! But if you'll change main() there:
-- cut --
main() {
A x;
x.f();
}
-- cut --
will produce error:
-- cut --
test.C: In function `int main()':
test.C:9: cannot declare variable `x' to be of type `A'
test.C:9: since the following virtual functions are abstract:
test.C:9: void A::f()
-- cut --
More exotic version:
-- cut --
#include <iostream>
struct A {
virtual void f () { std::cout << "A"; }
void g() { f(); }
};
struct B : virtual public A {
virtual void f () { std::cout << "B"; }
};
struct C : virtual public A {
virtual void f () { std::cout << "C"; }
};
struct D : virtual public B, virtual public C {
};
int main() {
D().g();
}
-- cut --
will be compiled without warnings (even with -Wall !!) while the same version
with the following main()
-- cut --
int main() {
D x;
x.g();
}
-- cut --
will produce error:
-- cut --
test.C: In function `int main()':
test.C:17: cannot declare variable `x' to be of type `D'
test.C:17: since the following virtual functions need a final overrider:
test.C:17: void B::f()
-- cut --
What's the difference there ???
P.S. Of course second program will hangs with message 'pure virtual method called'
P.P.S. egcs 1.1b still does not like the following program:
-- cut --
void *p=!!0;
main() {
}
-- cut --
which is correct according to latest (spring 1998) Bjarne. Who is wrong: Bjarne
or egcs ? I'm does not have ANSI C++ standard text here so I'm could not decide
:-(( When you'll use '1-1' instead of '!1' all will be compiled just fine...
And even just 1 will generate just warning, not error... Message is
-- cut --
test.C:1: initialization to `void *' from `bool'
-- cut --
More information about the Gcc
mailing list