我的两个课程是:
class sequence
{
public:
...
private:
int number_of_samples;
float* samples;
};
class FIR
{
public:
...
sequence* apply_filter(const sequence& f);
private:
int number_of_coefficients;
float* coefficients;
};
当我运行以下成员函数时:
sequence* FIR::apply_filter(const sequence& f)
{
ofstream output_sequence_file("output.txt");
output_sequence_file<<number_of_coefficients<<endl;
sequence* Vout = new sequence;
for(int i=0;i<number_of_coefficients;i++)
{
if (0==i) Vout->samples[i]=coefficients[i]*f.samples[i];
else Vout->samples[i]=coefficients[i] * f.samples[i] + Vout->samples[i-1];
output_sequence_file<<Vout->samples[i]<<endl;
}
}
我收到错误消息:&#39;样本&#39;是序列的私人成员。
有任何帮助吗? 谢谢
答案 0 :(得分:0)
将samples
移至class sequence
的公开部分,或声明FIR::apply_filter()
friend
class sequence
。除非已授予其特权,否则其他类或函数无法访问类的私有成员。