Hello, I got this error when running this code. I am running on Windows 7
64 bit.
#include <iostream>
>
> #include <memory>
>
> #include <thread>
>
> #include <mutex>
>
> #include <stdexcept>
>
>
>> template <class T> class A;
>
> template <> class A<int>;
>
>
>> class Base
>
> {
>
> public:
>
> virtual ~Base(void)
>
> {
>
>
>> }
>
>
>> static Base& instance()
>
> {
>
> std::lock_guard<std::mutex> guard(sMutex);
>
> //std::cout << x++;
>
> //pInstance.reset(new Base());
>
> std::cout << "Base\n";
>
> std::call_once
>
> (
>
> pInstance_onceFlag,
>
> [](){
>
> std::cout << "Base: managing object\n";
>
> pInstance.reset(new Base);
>
> std::cout << "Base: finish managing object\n";
>
> }
>
> );
>
> return *pInstance.get();
>
> }
>
>
>> template<class T>
>
> void printsome(T& obj)
>
> {
>
> A<T>::instance(obj);
>
> }
>
>
>>
>> private:
>
> explicit Base()
>
> {
>
> std::cout << "Base constructor\n";
>
>
>> }
>
> Base(const Base&);
>
> Base& operator=(const Base&);
>
>
>> //Initialize mutex
>
> static std::mutex sMutex;
>
>
>> //C++11 style to flag so that only can be called once
>
> static std::once_flag pInstance_onceFlag;
>
>
>> //Static variable for the one-and-only instance
>
> static std::unique_ptr<Base> pInstance;
>
>
>> //Ptr to object
>
> //template <class T>
>
> //std::unique_ptr<A<T>> kpInstance;
>
> };
>
> std::mutex Base::sMutex;
>
> std::once_flag Base::pInstance_onceFlag;
>
> std::unique_ptr<Base> Base::pInstance = nullptr;
>
>
>>
>> template<>
>
> class A<int>
>
> {
>
> public:
>
> static A& instance(int& obj)
>
> {
>
> std::lock_guard<std::mutex> guard(sMutex);
>
> std::call_once
>
> (
>
> pInstance_onceFlag,
>
> [&] ()
>
> {
>
> std::cout << "A: managing object\n";
>
> pInstance.reset(new A<int>(obj));
>
> }
>
> );
>
> return *pInstance.get();
>
> }
>
> virtual ~A()
>
> {
>
>
>> }
>
>
>> private:
>
> explicit A(int& obj)
>
> {
>
> std::cout << "A: "<< obj <<"\n";
>
> }
>
> A(const A&);
>
> A& operator=(const A&);
>
>
>> //Initialize mutex
>
> static std::mutex sMutex;
>
>
>> //C++11 style to flag so that only can be called once
>
> static std::once_flag pInstance_onceFlag;
>
>
>> //Static variable for the one-and-only instance
>
> static std::unique_ptr<A<int>> pInstance;
>
> };
>
>
>> std::mutex A<int>::sMutex;
>
> std::once_flag A<int>::pInstance_onceFlag;
>
> std::unique_ptr<A<int>> A<int>::pInstance = nullptr;
>
>
>
>
>> int main()
>
> {
>
> int x = 2;
>
> std::cout << "Main\n";
>
> Base::instance().printsome(x);
>
> std::cout << "Main exiting\n";
>
> return 0;
>
> }
>
>
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public