I
I
Insolent Muzzle2021-06-08 14:08:17
C++ / C#
Insolent Muzzle, 2021-06-08 14:08:17

How to copy the behavior of a type passed as a class template argument?

There is a conditional class MagicClass
. It can copy the behavior of the type passed to it by the template argument:

MagicClass<int>          some_var = 13;
MagicClass<std::string>  another_var = "Some Text";
MagicClass<AnotherClass> yet_another_var = /*Some magic*/;

How to implement such a class?
UPD: It should not only copy the = operator
SomeClass<int> some_var = 12;
some_var++;
some_var *= (11 + 11);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-06-08
@pluffie

Define a constructor with a template type for it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question