1
0

feat: inheritance constructor

This commit is contained in:
mandlm 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;
}

View File

@ -7,6 +7,7 @@
#include "delegate_constructor.h"
#include "if_constexpr.h"
#include "ifswitch.h"
#include "inheritance_constructor.h"
#include "initlist.h"
#include "null.h"
#include "range_based_for.h"
@ -32,6 +33,7 @@ int main(int argc, char **argv) {
chapter_2_tests.emplace_back(std::make_unique<RangeBasedForTest>());
chapter_2_tests.emplace_back(std::make_unique<VariadicTemplates>());
chapter_2_tests.emplace_back(std::make_unique<DelegateConstructor>());
chapter_2_tests.emplace_back(std::make_unique<InheritanceConstructor>());
for (auto &test : chapter_2_tests) {
std::cout << "\n" << test->name() << ":" << std::endl;