【发布时间】:2016-04-14 23:01:01
【问题描述】:
我有两个类Training 和Testing,其中Training 是基类,Testing 是Training 的派生类。
我有Testing类成员函数float totalProb(Training& classProb, Training& total),它有2个参数,都是Training类对象。代码:
void Testing::totalProb(Training& classProb, Training& total) {
_prob = (_prob * ((float)(classProb._nOfClass) / total._tnClass));
cout << "The probalility of the " << it->first << " beloning to " << classProb._classType << " is: " << _prob << endl;
}
这个函数的作用基本上是计算test1(Testing 类的对象)中每个文档属于class1(Training 类的对象)的概率。
所有Training 类(它是基类)变量都是Protected,所有Training 类函数都是Public。
当我尝试运行 test1.totalProb(class1, total); 时,我收到错误 Error C2248 'Training::_probCalc': cannot access protected member declared in class 'Training'。我无法解决这个问题。
【问题讨论】:
-
请制作一个更简单的代码示例 - 目前其中充满了不相关的内容,掩盖了您问题的本质。
-
@OliverCharlesworth 我让代码更简单了
-
不要使用 c 风格的演员表。
标签: c++ class c++11 inheritance