probably because RectF is a parameter in Brick's constructor.
Nope, it's because Brick has a RectF member, not because it was a part of the constructor paramter list.
In order for you to create a Brick using a default constructor, every member of Brick must be default constructable.
In order for a class or struct to be default constructable:
- All members of the class must be default constructable
- The class must have a constructor with an empty parameter list Brick(), Color(), RectF() defined
- If no other constructors are defined, the class does not need to define a default constructor
The last one means, if there are absolutely no constructors, the class or struct is default constructable, provided all members are also default constructable.
It is acceptable to just declare the default constructor as = default as long as all members of the class/struct are default constructable.
Brick() = default;
RectF() = default;
Later on, you may find that there are cases you store objects that aren't default constructable which as you found out, makes your class unable to be default constructed. The way around this would be to actually define a default constructor that isn't declared = default; and assign default values to the members that are not otherwise default constructable.
In the case of the RectF, you could have made a default constructor for Brick that just assigned zeros to your RectF member.
Code: Select all
#pragma once
#include "RectF.h"
#include "Colors.h"
#include "Graphics.h"
class Brick
{
public:
Brick() : rect(0.f, 0.f, 0.f, 0.f), c(Colors::Magenta){}
Brick(const RectF& rect_in, Color c_in);
void Draw(Graphics& gfx) const;
private:
RectF rect;
Color c;
bool isDestroyed = false;
};
Of course, it would probably be better to just give RectF a default constructor.
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