feat: inheritance constructor
This commit is contained in:
parent
3c3d8d7c26
commit
a3c2e3728c
@ -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)
|
||||
|
||||
|
11
chapters/chapter_02/include/inheritance_constructor.h
Normal file
11
chapters/chapter_02/include/inheritance_constructor.h
Normal 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";
|
||||
};
|
||||
};
|
22
chapters/chapter_02/src/inheritance_constructor.cpp
Normal file
22
chapters/chapter_02/src/inheritance_constructor.cpp
Normal 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;
|
||||
}
|
@ -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;
|
||||
|
Reference in New Issue
Block a user