我有两个并行类,一个解析 .xlsx 文件,一个解析 xls 文件。我自己编写了 xlsx 解析器,但继承自另一个 xls 解析器以使其适合我的类模型。到现在为止还挺好。
两个类最终都使用同一段代码,使用 rapidjson 创建一个 json 数组以插入到数据库中。但是,在xlsx端,一切正常,但在xls端,包含和使用rapidjson库会导致以下错误:
excelparser/lib/rapidjson/rapidjson.h:370:1: error: template class without a name
即使我从 xls.cpp 中删除所有代码并且只在 xls.h 中留下一个简单的#include,我也会遇到同样的错误。
头文件中的行是:
//! UTF-16 encoding.
/*! http://en.wikipedia.org/wiki/UTF-16
\tparam CharType Type for storing 16-bit UTF-16 data. Default is wchar_t. C++11 may use char16_t instead.
\implements Encoding
*/
template<typename CharType = wchar_t>
struct UTF16 { // <-- Line 370
typedef CharType Ch;
static Ch* Encode(Ch* buffer, unsigned codepoint) {
if (codepoint <= 0xFFFF) {
RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair
*buffer++ = static_cast<Ch>(codepoint);
}
else {
RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
unsigned v = codepoint - 0x10000;
*buffer++ = static_cast<Ch>((v >> 10) + 0xD800);
*buffer++ = (v & 0x3FF) + 0xDC00;
}
return buffer;
}
};