Is there anyway to distinguish the original name of a type from a typedef-name for that type?
For example:
class C1 {};
typedef C1 C2;
C1 and C2 both now name the same type. In code after the above, is there ever a case where an occurence of the name C1 refering to the type in question cannot be replaced with C2 (or visa versa)?
A programmer in modern C++ has two options for declaring new type aliases. The typedef keyword is used to declare new type aliases in the typical way. The using keyword is the new means of declaring new type aliases introduced in C++11.
Syntax. Note that a typedef declaration does not create types. It creates synonyms for existing types, or names for types that could be specified in other ways.
typedef in C++ typedef keyword is used to assign a new name to any existing data-type. For example, if we want to declare some variables of type unsigned int, we have to write unsigned int in a program and it can be quite hectic for some of us.
A typedef is scoped exactly as the object declaration would have been, so it can be file scoped or local to a block or (in C++) to a namespace or class.
A typedef creates an alias, and they are indistinguishable as a type. There are on the other hand some specific syntax constructs that require the real type and not the typedef-ed (declaration/definition of constructor/destructors...), but that is a different question. As a type they are indistinguishable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With