Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // test_template_variadic_inheritance.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <string>
- #include <iostream>
- #include <type_traits>
- class Base {
- std::string m_Value;
- public:
- Base(std::string some_value)
- : m_Value{ some_value } {
- }
- void PrintValue() {
- std::cout << m_Value << std::endl;
- }
- };
- class SimpleBase {
- public:
- SimpleBase() = default;
- void PrintValue() {
- std::cout << "simple base value " << std::endl;
- }
- };
- template<typename T>
- class Derived : public T {
- public:
- template< typename ... T_CTOR_ARGS >
- Derived(T_CTOR_ARGS ... args)
- : T ( std::forward<T_CTOR_ARGS>( args )... ) {
- }
- void SomeFunctionality() {
- T::PrintValue();
- }
- };
- template<typename T, typename ... ARGS>
- Derived<T> create_derived(ARGS... args) {
- return Derived<T>{ std::forward<ARGS>(args)... };
- }
- int main()
- {
- Derived<Base> base = create_derived<Base>(std::string{ "test" });
- Derived<SimpleBase> simple_base = create_derived<SimpleBase>( );
- base.PrintValue();
- simple_base.PrintValue();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement