Add a member function

In Class View, you can add a member function to any class. When you do this, a declaration is added to the header file, and a stub member-function body is added to the class's implementation file, which you can then modify.

To add a member function to a class:

  1. In Class View, expand the project node to display the classes in the project. (To open Class View, on the menu bar, choose View, Class View.)

  2. Open the shortcut menu for the class you want to add a member function to, and then choose Add, Add Function.

  3. Provide the appropriate details about the member function. For more information, see Add member function wizard.

  4. Choose the Finish button to generate the member function code.

In this section

Add member function wizard

This wizard adds a member function declaration to the header file. It also adds a stub member function implementation to the implementation file for the selected class.

Once you've added the member function using the wizard, you can edit the code in the development environment.

  • Return type

    Sets the return type for the member function you're adding. You can provide your own return type, or you can select from the list of available types. For information about the types, see Fundamental types.

char
double
float
int

long
short
unsigned char
unsigned int

unsigned long
void
HRESULT

  • Function name

    Sets the name of the member function you're adding.

  • Parameter type

    Sets the type of parameter you're adding for the member function, if the member function has parameters. You can provide your own parameter type, or you can select from the list of available types.

char
double
float

int
long
short

unsigned char
unsigned int
unsigned long

  • Parameter name

    Sets the name of a parameter you're adding for the member function, if the member function has parameters.

  • Parameter list

    Displays a list of parameters you've added to the member function. To add a parameter to the list, provide a type and name in the Parameter type and Parameter name boxes and select Add. To remove a parameter from the list, select the parameter and select Remove.

  • Access

    Sets the access to the member function. Access modifiers are keywords that specify the access other classes have to the member function. For more information about specifying access, see Member-access control. The member function access level is set to public by default.

    Check whether the new member function is static or virtual, and whether it's inline or pure. If you set the member function to be pure, the Virtual check box is selected, and the Inline check box becomes unavailable. The default is a nonstatic, nonvirtual member function.

    Option Description
    Static Specifies that the function acts like a global and can be called outside of the class, even without class instantiation. The member function has no access to non-static members. A member function specified as Static can't be virtual.
    Virtual Makes sure that the correct member function is called for an object, regardless of the expression used to make the member function call. A member function specified as Virtual can't be static.
    Pure Indicates that no implementation is supplied for the virtual member function being declared. Pure can be specified only on virtual member functions. A class that contains at least one pure virtual member function is considered an abstract class. Classes derived from the abstract class must implement the pure virtual member function or they, too, are abstract classes.
    Inline Instructs the compiler to insert a copy of the member function body into each place the member function is called. A member function specified as Inline can't be pure.
  • .cpp file

    Sets the file location where the stub member function implementation is written. By default, it's written to the .cpp file for the class to which the member function is added. Select the ellipsis button to change the file name. The member function implementation is added to the contents of the selected file.

  • Comment

    Provides a comment in the header file for the member function.

  • Function signature

    Displays the member function verbatim from the code when you select Finish. You can't edit the text in this box. To change the member function, change the appropriate boxes in the wizard.