Adding a Class (Visual C++)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Adding a Class (Visual C++).

To add a class in a Visual C++ project, in Solution Explorer, right-click the project, click Add, and then click Class. This opens the Add Class Dialog Box dialog box.

When you add a class, you must specify a name that is different from classes that already exist in MFC or ATL. If you specify a name that already exists in either library, Visual C++ displays a message that indicates that the specified name is reserved.

If your project naming convention requires you to use an existing name, then you can just change the case of one or more letters in the name because Visual C++ is case-sensitive. For example, although you cannot name a class CDocument, you can name it cdocument.

What Kind of Class Do You Want to Add?

In the Add Class dialog box, when you expand the Visual C++ node in the left pane several groupings of installed templates are displayed. The groups include CLR, ATL, MFC, and C++. When you select a group, a list of the available templates in that group is displayed in the middle pane. Each template contains the files and source code that are required for a class.

To generate a new class, select a template in the middle pane, type a name for the class in the Name box, and click Add. This opens the Add Class Wizard so that you can specify options for the class.

  • For more information about how to create MFC classes, see MFC Class.

  • For more information about how to create ATL classes, see ATL Simple Object.

Note

The template Add ATL Support to MFC does not create a class, but instead configures the project to use ATL. For more information, see ATL Support in an MFC Project.

To make a C++ class that does not use MFC, ATL, or CLR, use the C++ Class template in the C++ group of installed templates. For more information, see Adding a Generic C++ Class.

Two kinds of form-based C++ classes are available. The first one, CFormView Class creates an MFC class. The second one creates a CLR Windows Forms class.

See Also

Creating a Forms-Based MFC Application
Add Class Dialog Box
Creating Desktop Projects By Using Application Wizards
Adding Functionality with Code Wizards