【发布时间】:2013-04-27 21:46:07
【问题描述】:
我想我只需要另一双眼睛来找出我做错了什么。
这是错误:
bfgs_template.hpp:478:5: error: ‘di’ was not declared in this scope
bfgs_template.hpp:478:8: error: ‘b’ was not declared in this scope
这是代码的快照:
template<typename T>
void update_d();
template<typename T>
class BFGSB: public BFGS<T>{
protected:
double *di;
int b;
public:
friend void update_d<T>();
};
template<typename T>
void update_d(){
di[b] = 0.0;
}
顺便说一句。虽然我没有发布其余的代码。 di 已初始化,如果我让 update_d 成为该类的成员。一切顺利。
【问题讨论】:
-
您希望
friend声明发挥什么作用?将对BFGSB的实例的引用传递给update_d,它将能够对该实例的私有成员进行操作。
标签: c++ templates inheritance friend