I'm running Ubuntu Server 8.04 LTS on an x64 system.
Trying to compile this simple code, I get the following compile errors from GCC:
GuiKitWidget2.cpp: In member function âvoid HostedSubscriber<Host, Delivery, Cancellation>::OnDelivery()â:
GuiKitWidget2.cpp:53: error: âhost_â was not declared in this scope
GuiKitWidget2.cpp: In member function âvoid HostedSubscriber<Host, Delivery, Cancellation>::OnCancellation()â:
GuiKitWidget2.cpp:57: error: âsubscribable_â was not declared in this scope
GuiKitWidget2.cpp:58: error: âhost_â was not declared in this scope
GuiKitWidget2.cpp: In member function âvoid HostedSubscriberDeliveryOnly<Host, Delivery>::OnDelivery()â:
GuiKitWidget2.cpp:70: error: âhost_â was not declared in this scope
GuiKitWidget2.cpp: In member function âvoid HostedSubscriberDeliveryOnly<Host, Delivery>::OnCancellation()â:
GuiKitWidget2.cpp:74: error: âsubscribable_â was not declared in this scope
GuiKitWidget2.cpp:75: error: âhost_â was not declared in this scope
GuiKitWidget2.cpp: In member function âvoid HostedSubscriberCancellationOnly<Host, Cancellation>::OnCancellation()â:
GuiKitWidget2.cpp:88: error: âsubscribable_â was not declared in this scope
GuiKitWidget2.cpp:89: error: âhost_â was not declared in this scope
The file:
class Subscriber
{
public:
virtual void OnDelivery() = 0;
virtual void OnCancellation() = 0;
};
class Subscribable
{
public:
virtual void AddSubscriber(Subscriber *sub) = 0;
virtual void RemoveSubscriber(Subscriber *sub) = 0;
};
template<typename Host>
class HostedSubscriberBase : Subscriber
{
public:
HostedSubscriberBase() : host_(0), subscribable_(0) {}
void Start(Subscribable *sub, Host *host)
{
Stop();
if (sub != 0)
{
host_ = host;
subscribable_ = sub;
sub->AddSubscriber(this);
}
}
void Stop()
{
if (subscribable_)
subscribable_->RemoveSubscriber(this);
subscribable_ = 0;
host_ = 0;
}
bool Active() const
{
return subscribable_ != 0;
}
protected:
Host *host_;
Subscribable * subscribable_;
};
template<typename Host, void (Host::*Delivery)(), void (Host::*Cancellation)()>
class HostedSubscriber : public HostedSubscriberBase<Host>
{
public:
void OnDelivery()
{
host_->Delivery();
}
void OnCancellation()
{
subscribable_ = 0;
Host *h = host_;
host_ = 0;
(h->*Cancellation)();
}
};
template<typename Host, void (Host::*Delivery)()>
class HostedSubscriberDeliveryOnly : public HostedSubscriberBase<Host>
{
public:
void OnDelivery()
{
host_->OnDelivery();
}
void OnCancellation()
{
subscribable_ = 0;
host_ = 0;
}
};
template<typename Host, void (Host::*Cancellation)()>
class HostedSubscriberCancellationOnly : public HostedSubscriberBase<Host>
{
public:
void OnDelivery()
{
}
void OnCancellation()
{
subscribable_ = 0;
Host *h = host_;
host_ = 0;
(h->*Cancellation)();
}
};
class Foo
{
public:
void Func() {}
HostedSubscriberCancellationOnly<Foo, &Foo::Func> foo_;
};
Am I mad, or is GCC just horrily broken? MSVC (2008 sp1) compiles this particular code just fine.