Syntax
struct Point {
int x;
int y;
};Examples
C++ structs example
A focused example you can adapt while practising.
struct Point {
int x;
int y;
};Best practices
- Start with the smallest working example, then adapt it to your project.
- Use the language’s standard library and idioms before introducing extra dependencies.
At a glance
- Purpose
- Systems and general-purpose software
- File extension
- .cpp · .hpp
- Runs in
- Compiled native applications
- Usually used with
- Compiler and standard library
Specifications & further reading
Related C++ documentation
C++ Classes & RAII
Classes group data and functions. Constructors establish valid state. C++ uses RAII: an object owns a resource for its lifetime and releases it in its destructor.C++ class access control
C++ reference for c++ class access control.C++ constructor initializer lists
C++ reference for c++ constructor initializer lists.C++ destructors
C++ reference for c++ destructors.
Classes group data and functions. Constructors establish valid state. C++ uses RAII: an object owns a resource for its lifetime and releases it in its destructor.C++ class access control
C++ reference for c++ class access control.C++ constructor initializer lists
C++ reference for c++ constructor initializer lists.C++ destructors
C++ reference for c++ destructors.