- 论坛徽章:
- 0
|
回复 #5 FuriousFive 的帖子
FuriousFive ,您好
我的问题还是没有解决,
我把我的代码简化了一下,可不可以在帮我看看
//test.cc
#include <stdio.h>
using namespace std;
template< class T >
class Singleton
{
class InstanceHolder
{
public:
InstanceHolder() : mObject(0) {}
~InstanceHolder() { delete mObject; }
void set(T* p) { delete mObject; mObject = p; }
private:
T* mObject;
};
public:
static T* instance()
{
return mInstance.set(new T());
}
private:
static InstanceHolder mInstance;
Singleton();
};
class ServiceListener
{
public:
virtual ~ServiceListener()
{ }
virtual void serviceStarted() = 0;
virtual void serviceStopped() = 0;
};
void ServiceListener::serviceStarted()
{
printf("serviceStarted() event listener is not implemented.");
}
void ServiceListener::serviceStopped()
{
printf("serviceStarted() event listener is not implemented.");
}
class ServiceController;
typedef Singleton<ServiceController> ServiceKontrol;
class ServiceController : public ServiceListener
{
public:
ServiceController();
~ServiceController();
virtual void serviceStarted();
virtual void serviceStopped();
private:
bool started;
};
ServiceController::ServiceController() : started(false)
{
}
ServiceController::~ServiceController()
{
}
void
ServiceController::serviceStarted()
{
printf("service start\n");
}
void
ServiceController::serviceStopped()
{
printf("servicestop\n");
}
template<class T> typename ServiceKontrol::InstanceHolder ServiceKontrol::mInstance;
int main(int argc, char **argv)
{
ServiceKontrol::instance()->serviceStarted();
//ServiceController a;
//a.serviceStarted();
return 0;
}
[root@localhost flashdisk]# g++ -o test.o test.cc
test.cc: In static member function static T* Singleton<T>::instance() [with T = ServiceController]鈥?
test.cc:20: instantiated from singleton<ServiceController>::InstanceHolder Singleton<ServiceController>::mInstance鈥?
test.cc:20: instantiated from static T* Singleton<T>::instance() [with T = ServiceController]鈥?
test.cc:89: instantiated from here
test.cc:20: internal compiler error: in instantiate_decl, at cp/pt.c:11906
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccHFDXCH.out file, please attach this to your bugreport.
[root@localhost flashdisk]#
[ 本帖最后由 xgdyyf11071 于 2008-12-10 17:46 编辑 ] |
|