feat: delegate constructor
parent
db87dfcf1c
commit
3c3d8d7c26
|
@ -8,7 +8,8 @@ add_library(
|
|||
src/range_based_for.cpp
|
||||
src/structured_binding.cpp
|
||||
src/type_inference.cpp
|
||||
src/variadic_templates.cpp)
|
||||
src/variadic_templates.cpp
|
||||
src/delegate_constructor.cpp)
|
||||
|
||||
target_compile_features(chapter_02 PUBLIC cxx_std_20)
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "chapter_interface.h"
|
||||
|
||||
class DelegateConstructor : public ChapterTest {
|
||||
virtual void run() override;
|
||||
virtual const char *name() const override {
|
||||
return "Delegate constructor test";
|
||||
};
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
#include "delegate_constructor.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class Printer {
|
||||
private:
|
||||
std::string value;
|
||||
|
||||
public:
|
||||
Printer(const std::string &value) : value(value){};
|
||||
Printer(int value) : Printer(std::to_string(value)){};
|
||||
|
||||
void print() { std::cout << value << std::endl; }
|
||||
};
|
||||
|
||||
void DelegateConstructor::run() {
|
||||
std::cout << "print(\"hello\"): ";
|
||||
Printer("hello").print();
|
||||
|
||||
std::cout << "print(23): ";
|
||||
Printer(23).print();
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "constexp.h"
|
||||
#include "delegate_constructor.h"
|
||||
#include "if_constexpr.h"
|
||||
#include "ifswitch.h"
|
||||
#include "initlist.h"
|
||||
|
@ -30,6 +31,7 @@ int main(int argc, char **argv) {
|
|||
chapter_2_tests.emplace_back(std::make_unique<IfConstexprTest>());
|
||||
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>());
|
||||
|
||||
for (auto &test : chapter_2_tests) {
|
||||
std::cout << "\n" << test->name() << ":" << std::endl;
|
||||
|
|
Loading…
Reference in New Issue