T
Tony Johansson
Hello!
I wonder why I can't do a cout on a protected member of the base class
called Base. As long the variable has been declared as public or protected I
should be able to acces that varable called number.
I have two classes one class called Base and a derived class called Derived
as youu can see below.
//Main file
********
#include "base.h"
int main()
{
Derived d;
Base b;
d.printInfo(b);
return 0;
}
#include <iostream>
using namespace std;
//Base class
//*********
class Base
{
public:
Base(int num = 0) :number(0){};
protected:
int number;
};
//Derived class
//***********
class Derived : public Base
{
public:
Derived(){}
void printInfo(const Base& b)
{cout << b.number;} //Why can I not do
this??????????????????????????
};
//Thanks
//Tony
I wonder why I can't do a cout on a protected member of the base class
called Base. As long the variable has been declared as public or protected I
should be able to acces that varable called number.
I have two classes one class called Base and a derived class called Derived
as youu can see below.
//Main file
********
#include "base.h"
int main()
{
Derived d;
Base b;
d.printInfo(b);
return 0;
}
#include <iostream>
using namespace std;
//Base class
//*********
class Base
{
public:
Base(int num = 0) :number(0){};
protected:
int number;
};
//Derived class
//***********
class Derived : public Base
{
public:
Derived(){}
void printInfo(const Base& b)
{cout << b.number;} //Why can I not do
this??????????????????????????
};
//Thanks
//Tony