换编译器编译和使用log4cxx时遇到c2252错误
error C2252: an explicit instantiation of a template can only occur at namespace scope
搜索了一下解决方案,在log4cxx邮件列表有如下关于该bug解决方案的描述:
Hi Cory, This is how I did it: 1. Move all those LOG4CXX_LIST_DEF macros before the class definition. in telnetappender.h you will also need to move the typedef that precedes this macro. 2. If the compiler complains about KeySet not being member of LoggingEvent, just remove the scope (since we moved the type to outside the class in the previous step, these types no longer are inside the class) ex: change: LoggingEvent::KeySet set; to: KeySet set; 3. If the compiler complains about insert_iterator not being in the namespace std, add #include <iterator> to the include section of the source file 4. For some reason the VS2010 converter ‘forgot‘ to reference the lib files from apr,apr-util and xml, so i had to add them manually. Hope it helps, Daniel 我采取了一个比较简单粗暴的方式解决这个问题:在loggingevent.h中用
typedef std::vector<LogString> KeySet;
替换
//LOG4CXX_LIST_DEF(KeySet, LogString);
时间: 2024-10-06 00:54:09