以下示例代码可以在 MSVC 2012 中干净地编译:
struct S1
{
virtual void f() {}
};
template<typename T> struct S2 : S1
{
void f() override {}
};
template<> void S2<int>::f() override {}
但是,当我在代码上运行PC-Lint Plus(基于CLang)时,它报错:
template<> void S2<int>::f()^ override {}
test.cpp(11): error 4645: expected ';' at end of declaration
template<> void S2<int>::f() override {}^
test.cpp(11): error 4933: expected ';' after top level declarator
顺便说一句,如果我删除了 override
说明符,lint 会发出一条注释,指出它已丢失。
这是 lint/CLang 错误还是我做错了什么?
最佳答案
您只需要在函数声明中使用override
,而不是在类定义之外。只需删除它:
template<> void S2<int>::f() {}
关于c++ - Lint (CLang) 对 'override' 的特化投诉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43880158/