mercredi 1 décembre 2021

A class One with data members int a and char b inherits from another class Two with data members float f and int x

I need class definitions for class One and Two, where: 1. Objects of both the classes are able to access all the data members of both the classes. 2. Only the members of class One can access all the data members of both the classes.

//case 2
#include <iostream>
using namespace std;

class Two{
    public:
        float f;
        int x;
};

class One: public Two{
    private:
        int a;
        char b;
};

I have tried the 2nd part. Is it correct? And can you help me out with the 1st part.

Aucun commentaire:

Enregistrer un commentaire