Classes and Structs (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 Classes and Structs (C++).

This section introduces C++ classes and structs. The two constructs are identical in C++ except that in structs the default accessibility is public, whereas in classes the default is private.

Classes and structs are the constructs whereby you define your own types. Classes and structs can both contain data members and member functions, which enable you to describe the type's state and behavior.

The following topics are included:

The three class types are structure, class, and union. They are declared using the struct, class, and union keywords (see Defining Class Types). The following table shows the differences among the three class types.

For more information on unions, see Unions. For information on managed classes and structs, see Classes and Structs.

Access Control and Constraints of Structures, Classes and Unions

StructuresClassesUnions
class key is structclass key is classclass key is union
Default access is publicDefault access is privateDefault access is public
No usage constraintsNo usage constraintsUse only one member at a time

C++ Language Reference

Show: