錯誤處理--pure specifier can only be specified for functions
今天下載了log4cpp的源代碼,在VC6下編譯時出現錯誤:
..\..\include\log4cpp/Priority.hh(65) : error C2258: illegal pure syntax, must be '= 0'
..\..\include\log4cpp/Priority.hh(65) : error C2252: 'MESSAGE_SIZE' : pure specifier can only be specified for functions
..\..\include\log4cpp/threading/MSThreads.hh(160) : fatal error C1506: unrecoverable block scoping error
出錯的代碼位於Priority.hh中,代碼為:
static const int MESSAGE_SIZE = 8;
這個錯誤改起來很簡單,只要將這行代碼改為:
static const int MESSAGE_SIZE;
然后定位到Priority.cpp文件中,添加以下的代碼即可:
const int Priority::MESSAGE_SIZE = 8;
注意一下,如果這行代碼沒有放在namespace中時,需要在加上namespace,如:
const int log4cpp::Priority::MESSAGE_SIZE = 8;