我正在使用PC -lint(用于静态代码分析的好工具 - 请参阅 http://www.gimpel.com/)有关以下代码:

class ASD {
    protected:
        template<int N>
        void foo();
};

template<>
inline void ASD::foo<1>() {}

template<int N>
inline void ASD::foo() {}

PC-LINT给了我警告:

inline void ASD::foo<1>() {}
mysqldatabaseupdate.h(7) : Error 1060: protected member 'ASD::foo(void)' is not accessible to non-member non-friend functions

我相信代码很好,错误在绒侧,但是我认为皮棉工具确实很棒,而且比我不知道的更有可能。那么此代码还可以吗?

有帮助吗?

解决方案 2

该错误是在PC-lint本身中。它已在最新版本中修复。

其他提示

你有 只有一个 功能 foo 在你的 struct ASD 它在 protected 部分。它无法从非会员函数访问。同时 struct ASD 没有任何其他成员功能。所以没有人可以访问 foo, ,我相信这是该错误消息的原因。

尝试将您的结构更改为以下内容,例如:

class ASD {
    public:
        void bar() { foo<1>(); }
    protected:
        template<int N>
        void foo();
};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top