Share via


Adding a Member Function

OverviewHow Do I

Note   ClassWizard does not have the capability of adding a generic member function.

You can add a member function to any class using ClassView or WizardBar. The tools add a function declaration to the header file, and add a stub function to the class's implementation file, which you can then edit.

To add a member function using ClassView

  1. Select the class to which you want to add a function.

  2. With the mouse pointer over the selected class, click the right mouse button to display the shortcut menu, and choose Add Member Function.

    The Add Member Function dialog box appears.

  3. In the Function Type text box, type the function's return type.

  4. In the Function Declaration text box, type the function declaration. The Function Type text box contains the return type for the function, so here you type only the function name, followed by a list of the names and types of formal parameters enclosed in parentheses.

  5. Select an access specifier for the function from the Access group of options.

  6. If you want a static function, click the Static check box. Or, if you want a virtual function, click the Virtual check box.

  7. Click OK.

    This procedure adds a declaration to the header file for the class, and a corresponding function body in the implementation file for the class.

To add a member function with WizardBar

  1. Using WizardBar's Class drop-down list, select a class, then select Add Member Function.

  2. The Add Member Function dialog box prompts you for the Function Type and the Function Declaration.

    Specify whether the new member function will be public (default), protected, or private.

  3. You must also specify whether or not the function will be static, and whether or not it will be virtual. You can do so either by selecting the static or virtual check box, or by entering the word static or virtual in the Function Declaration. The default is a non-static, non-virtual function. For example, the following settings:

    • Function Type: BOOL

    • Function Declaration: Foo

    • Access: Public

    • Virtual: Yes (Selected)

    produce the following function declaration:

    virtual BOOL CAboutDlg::Foo();
    

See Also   Adding a Class, Adding a Member Variable, Overriding a Virtual Function, Adding a Message Handler, Deleting a Member Function, Navigating the Class Structure