Working with Visual C++ Code in Class Designer

Class Designer displays a visual design surface called a class diagram that provides a visual representation of the code elements in your project. You can use class diagrams to design and visualize classes and other types in a project.

In earlier versions of Visual Studio, Class Designer supported only the managed languages (Visual C# and Visual Basic). In Visual Studio 2008, Class Designer adds limited support for native C++ code, intended to be used only for visualization and documentation.

Class Designer supports the following C++ code elements:

  • Class (resembles a managed class shape, except that it can have multiple inheritance relationships)

  • Anonymous class (displays Class View's generated name for the anonymous type)

  • Template class

  • Struct

  • Enum

  • Macro (displays the post-processed view of the macro)

  • Typedef

Troubleshooting Type Resolution and Display Issues

Location of Source Files

Class Designer does not keep track of the location of source files. Therefore, if you modify your project structure or move source files in your project, Class Designer can lose track of the type (especially the source type of a typedef, base classes, or association types). You might receive an error such as Class Designer is unable to display this type. If you do, drag the modified or relocated source code to the class diagram again to redisplay it.

Update and Performance Issues

For Visual C++ projects, it might take 30 to 60 seconds for a change in the source file to appear in the class diagram. This delay might also cause Class Designer to throw the error No types were found in the selection. If you receive an error such as this, click Cancel in the error message and wait for the code element to appear in Class View. After you do this, Class Designer should be able to display the type.

If a class diagram fails to update with changes you have made in the code, you might need to close the diagram and open it again.

Type Resolution Issues

Class Designer might not be able to resolve types for the following reasons:

  • The type is in a project or assembly that is not referenced from the project that contains the class diagram. To correct this error, add a reference to the project or assembly that contains the type. For more information, see How to: Add or Remove References in Visual Studio (Visual Basic).

  • The type is not in the correct scope, so Class Designer cannot locate it. Ensure that the code is not missing a using, imports, or #include statement. Also ensure that you have not moved the type (or a related type) out of the namespace in which it was originally located. For more information, see Referencing Namespaces and Components.

  • The type does not exist (or has been commented out). To correct this error, ensure that you have not unintentionally commented out or deleted the type.

The error you are most likely to see for a type resolution issue is Code could not be found for one or more shapes in class diagram '<element>'. See the description of that error for more information.

Troubleshooting Specific Error Messages

For more information about troubleshooting specific error messages, see the error topics in Class Designer Error Messages.

Limitations for C++ Code Elements

  • When a Visual C++ project is loaded, Class Designer functions in a read-only manner. You can change the class diagram, but you cannot save changes from the class diagram back to the source code.

  • Class Designer supports only native C++ semantics. For Visual C++ projects compiled into managed code, Class Designer will only visualize code elements that are native types. Therefore, you can add a class diagram to a project, but Class Designer will not allow you to visualize elements in which the IsManaged property is set to true (that is, value types and reference types).

  • For Visual C++ projects, the Class Designer reads only the definition of the type. For example, assume that you define a type in a header (.h) file and define its members in an implementation (.cpp) file. If you invoke "View Class Diagram" on the implementation (.cpp) file, Class Designer displays nothing. As another example, if you invoke "View Class Diagram" on a .cpp file that uses an #include statement to include other files but does not contain any actual class definitions, Class Designer again displays nothing.

  • IDL (.idl) files, which define COM interfaces and type libraries, do not display in diagrams unless they are compiled to native C++ code.

  • Class Designer does not support global functions and variables.

  • Class Designer does not support unions. This is a special type of class in which the memory allocated is only the amount necessary for the union's largest data member.

  • Class Designer does not display basic data types such as int and char.

  • Class Designer does not display types that are defined outside of the current project if the project does not have correct references to those types.

  • Class Designer can display nested types but not the relationships between a nested type and other types.

  • Class Designer cannot display types that are void or that derive from a void type.

See Also

Concepts

Visual C++ Classes in Class Designer

Visual C++ Structures in Class Designer

Visual C++ Enumerations in Class Designer

Visual C++ Typedefs in Class Designer

Other Resources

Designing and Viewing Classes and Types

Working with Classes and Other Types

Working with Class Diagrams

Designing Classes and Types

Class Designer Error Messages