Vec_MD类是用VecMD_Impl实现的。使用pimple指针无法从实现类实现运算符
实现的类是:
class VecMD{
private:
VecMD_Impl *pimple;
public:
///other elements..//
///operators//
double& operator [] (int index){ //works
return pimple -> operator[](index);
}
VecMD& operator +=(const VecMD& Vec){ //errors
return pimple -> operator += (Vec);
}};
实现类是
class VecMD_Impl{
private:
double *p_;
int dim;
public:
////other elements....////
//opearators//
double& operator[](int index){
return p_[index];
}
VecMD_Impl& operator +=(const VecMD_Impl& Vec){
for(int i = 0 ; i <= Vec.dim; ++i){
p_[i] += Vec.p_[i];
}
return *this;
}};
是真的 - >在实现类上使用运算符?
如果我们如何在pimpl成语中使用它们是真的吗?
问题已解决
VecMD& operator += (const VecMD& Vec)
{
pimple -> operator +=(*Vec.pimple);
return *this;
}
实现类是一样的。