feat: inheritance constructor

This commit is contained in:
Michael Mandl 2023-11-05 12:06:16 +01:00
parent 3c3d8d7c26
commit a3c2e3728c
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
4 changed files with 37 additions and 1 deletions

View file

@ -9,7 +9,8 @@ add_library(
src/structured_binding.cpp
src/type_inference.cpp
src/variadic_templates.cpp
src/delegate_constructor.cpp)
src/delegate_constructor.cpp
src/inheritance_constructor.cpp)
target_compile_features(chapter_02 PUBLIC cxx_std_20)

View file

@ -0,0 +1,11 @@
#pragma once
#include "chapter_interface.h"
class InheritanceConstructor : public ChapterTest {
public:
virtual void run() override;
virtual const char *name() const override {
return "Inheritance constructor test";
};
};

View file

@ -0,0 +1,22 @@
#include "inheritance_constructor.h"
#include <iostream>
class BaseClass {
private:
int value;
public:
BaseClass(int value) : value(value){};
void print() { std::cout << value; };
};
class SubClass : public BaseClass {
public:
using BaseClass::BaseClass;
};
void InheritanceConstructor::run() {
std::cout << "SubClass(23).print(): ";
SubClass(23).print();
std::cout << std::endl;
}