小编nSv*_*v23的帖子

受保护的成员不能通过指针或对象访问

我有2类TrainingTesting,其中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)

基本上这个函数的作用是计算test1Testing类对象)中每个文档属于class1(类对象)的概率Training

所有Training类(即基类)变量Protected和所有Training类函数都是Public. …

c++ inheritance class c++11

7
推荐指数
1
解决办法
5762
查看次数

在std :: cout中递增变量时,指针未显示更新的值

#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)

c++ pointers operator-precedence

4
推荐指数
1
解决办法
94
查看次数

c ++中运算符的地址

当我执行以下操作时:

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)
  1. 为什么a具有相同的y地址?我知道,改变一个将改变ÿ也.
  2. 但你怎么看第2行?你读它作为地址的一个包含价值ÿ
  3. 这是否意味着ay共享相同的物理内存位置?或者是否有2个不同的内存位置具有相同的地址?

c++ c++11

0
推荐指数
1
解决办法
276
查看次数

标签 统计

c++ ×3

c++11 ×2

class ×1

inheritance ×1

operator-precedence ×1

pointers ×1