Greetings!
I am quite confused with the default constructor in tutorial 19 (Vec2.h) we made the default constructor (and never call it as far as i noticed) even tho we already made another constructor.
Code:
class Vec2
{
public:
Vec2() = default; //
Vec2(float x_in, float y_in); //
public:
float x;
float y;
}
I assume we've implemented the default constructor in case we want to initialize a vector without giving it values.
Off topic:
Chilli, i bought multiple courses of c++ before watching your tuts and you guessed it, i regret it. Every one of them had 5 stars! And every one of them had a teacher with a closed mouth barely talking and when they did you had to turn the volume up. Waste of money!
Have you ever thought about making a mobile video game and sending it to a publisher? (that's my goal) You do have the skills without doubt. It's up to you if you think you can make a good enough game. And with this occasion you could make some unity or unreal engine tutorials (unity has way better deals on royalties).
Constructor Qustion.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Constructor Qustion.
To the default constructor, there are a couple of reasons to have one and maybe a couple to not have one.
Reasons for having a default constructor in your class would be:
Reasons for having a default constructor in your class would be:
- You want to default initialize your object
- You want an array or vector of those objects
- You want to delay assigning values based on some conditions
- Your class should never be default initialized, all values must be initialized by outside sources through other constructors.
- You have no constructors at all and your data is public, this allows for aggregate initialization
- Ex: If Vec2 didn't have any constructors, you could do Vec2 pos = { 300,200 };
- You can use the curly brace initialization with classes with private data as long as you have a matching constructor Vec2( float X, float Y ), otherwise aggregate initialization doesn't work.
- Your class is a singleton and must be instantiated through an Instance() function for instance lol.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
-
- Posts: 115
- Joined: April 27th, 2012, 11:49 pm
Re: Constructor Qustion.
Nice explanation. You should add this to the sticky regarding constructors.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Constructor Qustion.
done.nG Inverse wrote:Nice explanation. You should add this to the sticky regarding constructors.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com