Operating System - Linux
1830201 Members
31537 Online
109999 Solutions
New Discussion

compiler have some problems with virtual functions

 
Varun_5
Occasional Advisor

compiler have some problems with virtual functions

Hi,
I am having big problems getting the final binary to link...
it seems to me that it is the compiler have some problems with virtual functions. If you look at the following small example to trigger the problem:
# /opt/aCC/bin/aCC -V
aCC: HP ANSI C++ B3910B A.03.55
#cat test.cc
class Foo
{
public:
virtual ~Foo();
Foo() {};
virtual void clear();
};

class Bar : public Foo
{
public:
virtual ~Bar() {};
Bar() : Foo() {};

virtual void clear() {
Foo::clear();
};
};
# aCC -c test.cc
# nm -u test.o

Undefined symbols from test.o:

typeid
Foo::~Foo()
Foo::clear()
Class tables [Vtable] dependent on key function: "__versioned_type_info::~__versioned_type_info()"

But if we compare this with other compilers we get:
# /opt/hp-gcc/bin/g++ -c test.cc
[tn202803@lit01:api] nm -u test.o
nm: test.o: no symbols

Please guide me through the issue.

Thanks in advance.
Varun
1 REPLY 1
Dennis Handly
Acclaimed Contributor

Re: compiler has some problems with unsat virtual functions

Why do you think your small example matches your application?

Your small example is illegal. The C++ Standard says 10.3(8), that if you declare a virtual function you must define it.

Therefore you must not use .h files where you never define virtual functions. You must define Foo::~Foo() & Foo::clear().

aCC6 has been enhanced to realize nothing is needed. aCC3 is stuck in a chicken and egg loop.