You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
525 B
Plaintext
22 lines
525 B
Plaintext
7 years ago
|
// structs are like classes, but everything is by default public
|
||
|
|
||
|
// Declaration
|
||
|
ObjectName structName {
|
||
|
|
||
|
// Declaration of variables
|
||
|
int a;
|
||
|
string b;
|
||
|
|
||
|
// Constructor
|
||
|
structName(new_a, new_b) {
|
||
|
a = new_a;
|
||
|
b = new_b;
|
||
|
}
|
||
|
|
||
|
// Implement any public functions below
|
||
|
};
|
||
|
|
||
|
// Accessing PUBLIC variables
|
||
|
ObjectName v = structName(5, "Hello"); // Creates a struct via the constructor
|
||
|
std::cout << v.a << " " << v.b << std::endl; // Prints to console "5 Hello"
|