C++ Class Inheritance with public members

Introduction

Derived class and objects of a derived class can access public members of a base class:

class MyBaseClass 
{ 
public: /*from  w  w w .ja  va 2 s  .c om*/
    char c; 
    int x; 
}; 

class MyDerivedClass : public MyBaseClass 
{ 
    // c and x also accessible here 
}; 

int main() 
{ 
    MyDerivedClass o; 
    o.c = 'a'; 
    o.x = 123; 
} 



PreviousNext

Related