C ++ empty class or typedef

I am currently using something similar in my code:

class B : public A<C> { };

Wouldn't it be better to use typedef?

typedef A<C> B;
+5
source share
7 answers

It depends. If you want to A<C>, and Bhave been excellent, but related types Bshould expand A<C>. If you want them to be identical, you should use typedef. Can you provide more context?

+16
source

It depends on what you want. If you use different classes to configure template metaprograms, it’s better to create one B.

, , typedef, .

+4

, , typedef.

+2

. , typedef :

typedef A<C> B;
func(B param) {...}
...
A<C> var;
func(var);
+2

, , , A<C>. , typedef - . , , .

, . typedef . , .

, , , A, .

+1

, , .

C ++ typedefs are not "strong", which basically means that Bthey A<C>will be of the same type. If you want to distinguish between two, use a class.

Various options for a strong typedef can be found on the Internet, boost one , for example.

+1
source

For completeness, I want to add one more point: C

class B : public A<C> { };

you can easily forward ad B:

class B;
void func(B param);
0
source

All Articles