C++ typedefs in Class Designer
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
Typedef statements create one or more layers of indirection between a name and its underlying type. Class Designer supports C++ typedef types, which are declared with the keyword typedef
, for example:
typedef class coord
{
void P(x,y);
unsigned x;
unsigned y;
} COORD;
You can then use this type to declare an instance:
COORD OriginPoint;
Class and struct shapes
In Class Designer, a C++ typedef has the shape of the type specified in the typedef. If the source declares typedef class
, the shape has rounded corners and the label Class. For typedef struct
, the shape has square corners and the label Struct.
Classes and structures can have nested typedefs declared within them. In Class Designer, class and structure shapes can show nested typedef declarations as nested shapes.
Typedef shapes support the Show as Association and Show as Collection Association commands on the right-click menu (context menu).
Class typedef example
class B {};
typedef B MyB;
Struct typedef example
typedef struct mystructtag
{
int i;
double f;
} mystruct;
Unnamed typedefs
Although you can declare a typedef without a name, Class Designer doesn't use the tag name that you specify. Class Designer uses the name that Class View generates. For example, the following declaration is valid, but it appears in Class View and Class Designer as an object named __unnamed:
typedef class coord
{
void P(x,y);
unsigned x;
unsigned y;
};
Note
Class Designer does not display typedefs whose source type is a function pointer.