Course Object Oriented Programming

Struct in C++

Course's Page 3 min Text by
User Image
Allan Garcia

In this class, we will see how structs work in C++.

Structures in C++

The way to define structs in C++ is similar to the way to define them in C. However, C-structs do not allow the programmer to use much of the Object-Oriented Programming concepts.

These are the main differences between structs in C++ and C:

  1. To declare a variable, you don't need the name struct;
  2. Allows methods (actions that objects can perform);
  3. Allows inheritance;
  4. Allows more types of polymorphisms.

Definition of a Struct in C++

Very similarly to C, to define a struct in C++, it is done:

struct <name> {
    // attributes and