c++ - Does this class act in the same way of its parent? -
c++ - Does this class act in the same way of its parent? -
i define template class this:
template <typename a, typename b> class { ~~~ };
and want utilize something<x, y>
. isn't neat, did this:
typedef something<x, y> somenewthing;
however, have problem yet. forwarding declaration of somenewthing form.
class x; class y; template <typename a, typename b> class something; typedef something<x, y> someappropriatenewname;
it inconvenient write in every header contains class. so, rather using of typedef, seek using inheritance.
class someappropriatenewname : public something<x, y> {};
except inheritance, empty class. forwards declaration this.
class someappropriatenewname;
it seems should work correctly.
does somenewthing
deed in same way something<x, y>
do?
does class deed in same way of parent? isn't there difference?
someappropriatenewname
has few differences. of can fix.
someappropriatenewname
should forwards constructors , other special fellow member functions parent.
if delete someappropriatenewname *
something<x, y> *
invoke undefined behavior without virtual
destructor. in practice, if someappropriatenewname
empty may fine.
someappropriatenewname
not pattern-match template overloads something<x, y>
does. distinct type. work pretty function argument matching (there slight differences), if pass to:
template<class t> struct is_something:std::false_type{}; template<class x, class y> struct is_something<something<x,y>>:std::true_type{};
then something<x, y>
gives true, while someappropriatenewname
gives false.
round-tripping void*
has go exact same type, unless both types standard layout think.
c++ templates inheritance
Comments
Post a Comment