February 25, 2021
Hot Topics:

Visual C++ Class Designer

  • By Nick Wienholt
  • Send Email »
  • More Articles »

Back in 2005, when covering the upcoming release of Visual C++ 2005, the use of the Class Designer to document and create C++ code was discussed, but unfortunately this functionality was pulled in the Beta 2 release of Visual C++ 2005. With Visual C++ 2008, support for C++ in the Class Designer is back, but with a few limitations. Getting the bad news out of the way first, the biggest surprise is that managed C++ classes are not supported by the Class Designer, and only native types can be displayed. The second major limitation is that the Class Designer has no support for modifying the displayed types using the Class Designer surface, unlike C# and Visual Basic.NET which support a bi-directional design experience where modifications in the Class Designer are reflected in code.

With these major limitations out of the way, it's worth looking at how much the Class Designer can actually do for C++ developers. The range of native C++ constructs that the Class Designer can display is quite impressive. Starting with a simple example, consider the following native C++ type definition:

class NativeClass
   NativeClass(void) {};
   ~NativeClass(void) {};
   int PublicInt;
   virtual char* GetString(int number) {return NULL;}
   ///<summary>Always returns zero</summary>
   inline int GetInt() {return 0;}
   double PrivateD;

To view this type in the Class Designer, simply select the header file in Solution Explorer, and click the view Class Diagram button, which is located in a toolbar at the top of the Solution Explorer window, as shown in Figure 1.

Figure 1: Basic Class Diagram View

Figure 1 shows the default display for a type on the Class Designer surface, and the Class Designer toolbar is also visible in Figure 1. As is apparent, the default view is fairly useless, and it will generally be necessary to change the display layout to get some useful information. By clicking on the small double-arrow head located near the name of the class (circled in Figure 2), detailed information on the member variables and methods of the class can be seen, as shown in Figure 2.

Click here for a larger image.

Figure 2: Class Diagram Detailed View

Figure 2 also shows the Properties window and Class Details windows displayed, and with this information, the visibility, return type, and summary of all methods and member variables can be seen. When a method is selected in the Class Details window, further information about whether the method is virtual or inline can be seen in the Properties window. The detailed class information in Figure 2 is achieved by selecting the Display Full Signature option from the Class Designer toolbar. The other two display options are Display Name, which only shows method and member variable names as the option suggest, and Display Name and Type, which shows all the information in Figure 2 with the exception of parameters to methods.

Visual C++ supports having multiple Class Diagrams in a project, with each Class Diagram having the file extension .cd, and maintaining all the layout options that have been selected when the diagram was created. To add a new diagram to a project, simply select a new header file containing a native class definition, and click the View Class Diagram button. To add other types to an existing diagram, the header file containing the type definition needs to be dragged onto the Class Designer design surface. Doing this will add all the types declared in the header files onto the design surface, and those types that are not required can be selected and deleted.

Apart from diagramming an existing application, one of the most useful features of the Class Designer is its ability to navigate around the methods and member variables in a complex code base. Whereas most code bases will follow some convention about how to structure a class across a header and implementation file, code bases that have been around for a long time can suffer from developers who seem intent on hiding the implementation for a method as far away from its header file as possible. By right-clicking on any method or type in the Class Designer and selecting View Code from the context menu, the header or implementation file that contains the implementation will be navigated to, regardless where it is located inside the project.

Page 1 of 2

This article was originally published on October 2, 2007

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date