Inherit from classes passed to constructor as a template parameters an inherit from them

hshsvagen

I want to have something like that:

template<class... Args>
class MyClass : public Args
{
    MyClass<class... Args>(/*some parameters*/)
    { }
}

// ana then:
MyClass<Base1, Base2, Base3>(/*some arguments*/)

That i want to dynamic_cast to Base1 or etc. and to use his methods.

I know that this code will not work, but do you have any ideas how to do it?

Rian Quinn

This works fine:

struct Base1
{};
struct Base2
{};
struct Base3
{};

template<class... Args>
struct MyClass : public Args...
{};

MyClass<Base1, Base2, Base3> mc;

There is no need for the <> in your constructor, you are missing "..." after public Args and you are missing a ";" at the end of your class definition.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From

Inherit from const type passed as template parameter

From Dev

Is there a way to inherit parameters from a parent class's constructor?

From Dev

inherit from a class constructor javascript

From Dev

Inherit constructor from std::tuple

From Dev

Conversion in template from Classes inherit a base class to base

From Dev

Is it legal for class template specialisations to inherit from different base classes?

From Dev

How to inherit from SQLAlchemy classes and own classes

From Dev

Flask: Template in Blueprint Inherit from Template in App?

From Dev

Inherit from class template nested in template argument

From Dev

How to inherit class variable type from constructor?

From Dev

JavaScript : Inherit constructor properties from Parent Class

From Dev

C# how to inherit from default constructor

From Dev

ArrayList of Objects That Inherit from Parent Classes in Java

From Dev

Inherit two classes and implement from interface separately

From Dev

Should Meta Classes in Models Inherit From Object

From Dev

Do all Type classes inherit from RuntimeType?

From Dev

Not inherit some (chosen) methods from derived classes

From Dev

catching classes that do not inherit from BaseException is not allowed

From Dev

How to make a UITextField Inherit from two classes?

From Dev

Inherit same function name from several classes

From Dev

Is it possible to inherit from multiple abstract classes in Java?

From Dev

Class that can inherit from two different classes

From Dev

Template specialisation inherit from specific subclass

From Dev

c++ inherit from a template struct

From Dev

Do Kotlin classes that inherit from Java classes also inherit from Any?

From Dev

why classes can inherit from an another class if they already inherit from Object?

From

Why doesn't a class having private constructor prevent inheriting from this class? How to control which classes can inherit from a certain base?

From Dev

How can a template class inherit from a nested template class

From Dev

Python - Inherit from class which inherit Model

Related Related

  1. 1

    Inherit from const type passed as template parameter

  2. 2

    Is there a way to inherit parameters from a parent class's constructor?

  3. 3

    inherit from a class constructor javascript

  4. 4

    Inherit constructor from std::tuple

  5. 5

    Conversion in template from Classes inherit a base class to base

  6. 6

    Is it legal for class template specialisations to inherit from different base classes?

  7. 7

    How to inherit from SQLAlchemy classes and own classes

  8. 8

    Flask: Template in Blueprint Inherit from Template in App?

  9. 9

    Inherit from class template nested in template argument

  10. 10

    How to inherit class variable type from constructor?

  11. 11

    JavaScript : Inherit constructor properties from Parent Class

  12. 12

    C# how to inherit from default constructor

  13. 13

    ArrayList of Objects That Inherit from Parent Classes in Java

  14. 14

    Inherit two classes and implement from interface separately

  15. 15

    Should Meta Classes in Models Inherit From Object

  16. 16

    Do all Type classes inherit from RuntimeType?

  17. 17

    Not inherit some (chosen) methods from derived classes

  18. 18

    catching classes that do not inherit from BaseException is not allowed

  19. 19

    How to make a UITextField Inherit from two classes?

  20. 20

    Inherit same function name from several classes

  21. 21

    Is it possible to inherit from multiple abstract classes in Java?

  22. 22

    Class that can inherit from two different classes

  23. 23

    Template specialisation inherit from specific subclass

  24. 24

    c++ inherit from a template struct

  25. 25

    Do Kotlin classes that inherit from Java classes also inherit from Any?

  26. 26

    why classes can inherit from an another class if they already inherit from Object?

  27. 27

    Why doesn't a class having private constructor prevent inheriting from this class? How to control which classes can inherit from a certain base?

  28. 28

    How can a template class inherit from a nested template class

  29. 29

    Python - Inherit from class which inherit Model

HotTag

Archive