Difference between revisions of "Beginner C++ Game Programming Tutorial 14"
(→Aggregate Initialization {}) |
(→Aggregate Initialization {}) |
||
Line 11: | Line 11: | ||
==== Aggregate Initialization <code>{}</code> ==== | ==== Aggregate Initialization <code>{}</code> ==== | ||
− | With the <code>struct Location</code> (and later, <code>class</code>), we didn't define any constructors, so all we had was the default do-nothing constructor that is generated by the compiler. In order to | + | With the <code>struct Location</code> (and later, <code>class</code>), we didn't define any constructors, so all we had was the default do-nothing constructor that is generated by the compiler. In order to initialize a <code>Location</code> at one point in the video, Chili used something like <code>Location loc = {69,69};</code>. This is allowed, but the data type being initialized must satisfy certain conditions. Namely, it must have only <code>public</code> data members and it must have no constructors defined. For the full details on the requirements, see [http://en.cppreference.com/w/cpp/language/aggregate_initialization this page]. The brace <code>{}</code> initialization can be used for <code>class</code>es etc. that have constructors as well, but then the parameters have to conform to the constructor(s) and it will just call the applicable constructor. |
== Video Timestamp Index == | == Video Timestamp Index == |
Revision as of 19:31, 26 November 2016
This is a two-part tutorial in which we tackle a game with a little more substance--the Snake Game. Grids and arrays galore. Majestic.
Contents
Main Concepts Taught
-
struct
vsclass
- Inner (nested)
class
es -
operator
overloading
Other New(ish) Things
There was a bunch of other newish bullshit that I used, some of which I didn't go into much depth on. For those of you who give a shit, here is some extra info.
Aggregate Initialization {}
With the struct Location
(and later, class
), we didn't define any constructors, so all we had was the default do-nothing constructor that is generated by the compiler. In order to initialize a Location
at one point in the video, Chili used something like Location loc = {69,69};
. This is allowed, but the data type being initialized must satisfy certain conditions. Namely, it must have only public
data members and it must have no constructors defined. For the full details on the requirements, see this page. The brace {}
initialization can be used for class
es etc. that have constructors as well, but then the parameters have to conform to the constructor(s) and it will just call the applicable constructor.
Video Timestamp Index
Video (a)
Video (b) (coming soon!)
Homework
To be announced!