Я реализую класс Singleton для ведения журнала. Я объявляю static logging_instance_
для создания только одного экземпляра для имени класса support_service::logging_service
.
Экземпляр вызова Service_logging класса support_service::logging_service
, который объявляет статическую переменную ::logging_instance_
, но показывает ошибку
undefined reference to `support_service::logging_service<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>::logging_service()'
collect2: ld returned 1 exit status
support_service.hpp
namespace support_service
{
template<typename PATH = std::string , typename LEVEL = int>
class logging_service
{
public:
static boost::shared_ptr<logging_service<PATH,LEVEL> > instance();
....
private:
logging_service();
logging_service(const logging_service<PATH,LEVEL>&);
static boost::shared_ptr<logging_service<PATH,LEVEL> > logging_instance_;
};
}
template<typename PATH, typename LEVEL>
boost::shared_ptr<logging_service<PATH,LEVEL> > logging_service<PATH,LEVEL>::instance()
{
if(logging_instance_.get() == NULL)
logging_instance_ = boost::shared_ptr<logging_service<PATH,LEVEL> >(new logging_service<PATH,LEVEL>``());
return logging_instance_;
}
service_logging.hpp
using namespace support_service;
template<typename PATH, typename LEVEL>
boost::shared_ptr<logging_service<PATH,LEVEL> >support_service::logging_service<PATH,LEVEL>::logging_instance_;
namespace service_logging
{
template<typename PATH = std::string, typename LEVEL = int>
class service_logging
{
public:
service_logging();
bool set_logging(PATH file_path);
};
}
template<typename PATH, typename LEVEL>
bool service_logging<PATH,LEVEL>::set_logging(PATH file_path)
{
boost::shared_ptr<logging_service<PATH,LEVEL> > logging_ = logging_service<PATH,LEVEL>::instance();
...
}