我有2类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;
}
Run Code Online (Sandbox Code Playgroud)
基本上这个函数的作用是计算test1(Testing类对象)中每个文档属于class1(类对象)的概率Training。
所有Training类(即基类)变量Protected和所有Training类函数都是Public. …
#include <iostream>
#include <string>
using namespace std;
int main()
{
int a = 5;
int& b = a;
int* c = &a;
cout << "CASE 1" << endl;
cout << "a is " << a << endl << "b is " << b << endl << "c is " << *c << endl;
b = 10;
cout << endl << "a is " << a << endl << "b is " << b << endl << "c is " << …Run Code Online (Sandbox Code Playgroud) 当我执行以下操作时:
1. int y = 5;
2. int &a = y;
3. cout << &a << endl; // the address of a is the same address of y
4. cout << a << endl; // this has the value of y, which is 5.
Run Code Online (Sandbox Code Playgroud)