Hi

Please have a look on the code below. The statement in red is giving all those errors. I'm learning inheritance. So, it means whatever I'm trying to do isn't allowed but what is so bad about it that it's illegal to do? Could you please help with it? Thank you.

Code:
// pubpriv.cpp
// tests publicly- and privately-derived classes

#include <iostream>
#include <cstdlib>

using namespace std;

////////////////////////////////////////////////////////////////
class A                  //base class
{
   private:
      int privdataA;
   protected:
      int protdataA;
   public:
      int pubdataA;
};
////////////////////////////////////////////////////////////////
class B : public A       //publicly-derived class
{
   public:
      int pubdataB = pubdataA;
   public:
      void funct()
         {
         int a;
         //a = privdataA;
         a = protdataA;
         a = pubdataA;
         }
};
////////////////////////////////////////////////////////////////

class C : private A
{
   public:
      void funct()
         {
         int a;
         //a = privdataA;
         a = protdataA;
         a = pubdataA;
         }
};
////////////////////////////////////////////////////////////////

int main()
{
   int a;

   A objA;
   objA.pubdataA = 5;
   B objB;

   //a = objB.privdataA;
   //a = objB.protdataA;
   a = objB.pubdataB;

   C objC;
   //a = objC.privdataA;
   //a = objC.protdataA;
   //a = objC.pubdataA;

   cout << a << endl;

   system("pause;");
   return 0;
}
Errors:
Code:
23|error: 'A::pubdataA' cannot appear in a constant-expression|
23|error: ISO C++ forbids initialization of member 'pubdataB'|
23|error: making 'pubdataB' static|
23|error: ISO C++ forbids in-class initialization of non-const static member 'pubdataB'|
||=== Build finished: 4 errors, 0 warnings ===|