TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  PCA#015Checked automatically with code checker

This rule is Obsolete
Synopsis:Do not combine a class, enum or struct definition with typedef
Severity Level:9
Category:Parts of C++ to Avoid


In C typedefs of structs, classes and enums are used for notational convenience. For example a struct is usually defined and used in C in the following way:

typedef struct optional_tag
{ ... } FOO_STRUCT;

FOO_STRUCT foo_str;

Without using the typedef the use of the struct would have been longer (an extra struct keyword is needed):

{ ... };

struct FOO_STRUCT foo_str;

In C++ the extra struct keyword is not needed anymore. In other words, the following definition and use of a struct compiles fine:

{ ... };

FOO_STRUCT foo_str;
So there is no need to use the typedef for the definition of a struct, class, enum or union in C++. This does not mean that typedefs should be avoided in general.