Hi all,
I am trying to compile qpidc 0.20 on AIX, and have come across a strange
issue... Compiling the qpid/framing/AMQP_ServerProxy.o object, the compiler
produces the following error:
"qpid_build/qpidc-0.20/src/qpid/framing/Handler.h", line 52.47: 1540-0407 (S)
The base class "Handler" contains a circular reference back to "Functor".
The relevant code in the Handler.h header is:
31 template <class T>
32 struct Handler {
...
48 /** Adapt any void(T) functor as a Handler.
49 * Functor<F>(f) will copy f.
50 * Functor<F&>(f) will only take a reference to x.
51 */
52 template <class F> class Functor : public Handler<T> {
53 public:
54 Functor(F f, Handler<T>* next=0) : Handler<T>(next), functor(f) {}
55 void handle(T t) { functor(t); }
56 private:
57 F functor;
58 };
...
So, the struct Handler contains nested class Functor, which extends the
enveloping struct. This is not possible in C++ (at least not without forward
declaration) since the enveloping class is not yet complete at the time of the
nested class declaration.
Simple test:
struct base
{
int bla;
class extended : public base
{
public:
extended() {}
};
};
int main()
{
return 0;
}
produces on AIX (xlC compiler):
"circular.cpp", line 5.27: 1540-0407 (S) The base class "base" contains a
circular reference back to "extended".
and on Linux (CentOS, gcc):
circular.cpp:6: error: invalid use of incomplete type âstruct baseâ
circular.cpp:2: error: forward declaration of âstruct baseâ
I am baffled... how does this ever compile? I know it does, since I compiled it
myself (0.18, few months back) on Linux :|.
Regards,
Ales