我有这样的课:
#include "Blarg.h"
// ...
class Foo : public Bar {
// ...
static double m_value;
// ...
};
还有一个是这样的:
template<class X, class Y>
class Blarg : public Bar {
// ...
void SetValue(double _val) { Foo::m_value = _val; }
// ...
};
由于Foo
'sm_value
是私有的(我想保持这种状态),我想我会将该SetValue
函数声明为Foo
类的朋友,以便它可以在需要时访问静态成员。
我已经尝试在Foo
的公共区域内按照这些方式声明:
template<class X, class Y> friend void Blarg<X, Y>::SetValue(double _val);
template<class X, class Y> friend void Blarg::SetValue(double _val);
friend void Blarg::SetValue(double _val);
...但是编译没有运气。如果可能的话,正确的语法是什么?