samedi 30 septembre 2017

c++11 inheritance : public BaseClass

I'm not familiar with the c++11 inheritance notation :public BaseClass I see in

Stroustruup's C++ Programming Language

I thought specifying public before the base class name would publicize the base class members. However, it doesn't and I have to publicize them myself using public:

What is the purpose of :public BaseClass? I wrote some code to try and understand this

#pragma once

#ifndef ARITHMETIC_H
#define ARITHMETIC_H

class Arithmetic
{
   virtual void* add(void* operand_one, void* operand_two) = 0;
   virtual void* subtract(void* operand_one, void* operand_two) = 0;
   virtual void* multiply(void* operand_one, void* operand_two) = 0; 
   virtual void* divide(void* numerator, void* denominator) = 0; 
   virtual ~Arithmetic() {} 
};

#endif

#pragma once
#ifndef MATH_H
#define MATH_H

#include "Arithmetic.h"

class Math : public Arithmetic
{
public:
  void* add(void* operand_one, void* operand_two);
  void* subtract(void* operand_one, void* operand_two);
  void* multiply(void* operand_one, void* operand_two);
  void* divide(void* numerator, void* denominator);
  Math();
  ~Math();
};

void* Math::add(void* operand_one, void* operand_two)
{

}

void* Math::subtract(void* operand_one, void* operand_two)
{

}

void* Math::multiply(void* operand_one, void* operand_two)
{

}

void* Math::divide(void* numerator, void* denominator)
{

}

Math::Math() // can't; base class constructor is private
{

}

Math::~Math() // can't; base class destructor is private
{

}

#endif

What does :public BaseClass do?

Aucun commentaire:

Enregistrer un commentaire