protected members are not accessible through a pointer or object
You are trying to access the member of an other instance of your mother class:
classProb
, but inheritance make you able to access protected member of your own parent class only.
One way to correcting (but it strongly depend of what you are trying to do) is to put an getter of _probClass
in your Training class and call it in your test, for instance for the _probCalc member:
public:
(Type) Training::getProbCalc() {
return _probCalc;
}
the to change your call in the loop:
for (it3 = classProb.getProbCalc().begin(); it3 != classProb.getProbCalc().end(); it3++)
If you are trying to acces your own member inherited by your mother instance just call them directly. For instance:
for (it3 = _probCalc().begin(); it3 != _probCalc().end(); it3++)
Please consider the following minimal example you could have created:
class Base
{
public:
Base(int x = 0)
:m_x(x)
{}
protected:
int m_x;
};
class Derived : public Base
{
public:
Derived(Derived& der)
{
this->m_x = 1; // works
Base base;
// int i = base.m_x; // will not work
Derived works(base);
int i = works.m_x; // also works
}
Derived(Base& base)
: Base(base) // Base(base.m_x) will not work
{
}
};
The cpp reference says the following (https://en.cppreference.com/w/cpp/language/access) in the chapter Protected member access:
A protected member of a class Base can only be accessed
- by the members and friends of Base
- by the members and friends (until C++17) of any class derived from Base, but only when operating on an object of a type that is derived from Base (including this)