Я хочу получить доступ к переменным из унаследованных классов. Однако компилятор выдает ошибку: furniture.cpp: 55: 9: error: 'int stool :: n_StoolLegs' является закрытым в этом контексте one.n_StoolLegs -1 ;.
Это домашнее задание, однако, оно говорит, что мне нужно использовать 4 переменные типа стул. Так я унаследовал класс. Может быть, есть другой вариант для изменения унаследованных переменных?
мебель .hpp
#include <ostream>
#include <string>
#ifndef FURNIURE_HPP
#define FURNITURE_HPP
class stool{
private:
int n_StoolLegs;
int n_seats;
public:
void setStoolLegs(int);
int getStoolLegs();
void setSeats(int);
int getSeats();
};
class table {};//not relevant
class furniture: public stool, public table
{
private:
stool one;
stool two;
stool three;
stool four;
table first;
public:
furniture(){
one.setStoolLegs(4);
one.setSeats(1);
void makeMoreHipster();
};
#endif
furniture.ccp:
#include <iostream>
#include "furniture.hpp"
//begin stool
void stool::setStoolLegs (int nLegs){
n_StoolLegs = nLegs;
};
int stool::getStoolLegs(){
return n_StoolLegs;
};
void stool::setSeats (int nSeats){
n_seats = nSeats;
};
int stool::getSeats(){
return n_seats;
};
//end stool//
// begin table
//not relevant
// end table
//start furniture
void furniture::makeMoreHipster(){
one.n_StoolLegs -1;
};
// end furniture//