I define a initializer list ctor (sequence ctor) in a class and give it a default argument like this:
class Box
{
public:
Box(std::initializer_list<XMFLOAT3> vertices = {XMFLOAT3(), XMFLOAT3(), XMFLOAT3(), XMFLOAT3(), XMFLOAT3(), XMFLOAT3(), XMFLOAT3(), XMFLOAT3()});
~Box();
void SetVertices(std::initializer_list<XMFLOAT3> vertices);
XMFLOAT3 (&GetVertices())[8];
Mesh &GetMesh() { return mMesh; }
private:
XMFLOAT3 mVertices[8];
Mesh mMesh;
};
but when I put an object of type Box inside another class the compiler complains that there's no default ctor available. Why?
EDIT if I call the default ctor into the containing class ctor's initialization list:
Bone::Bone(std::string const &name) : mName(name), mCollisionBox{}
{
}
(I understand that when an initializer_list ctor is present the brace notation calls the default ctor first, not the initializer_list ctor with an empty list) it calls the default ctor.
The default ctor is also called if I explicitly call it:
Bone::Bone(std::string const &name) : mName(name), mCollisionBox()
{
}
I'm using VisualC++ with Visual studio 2017 that's really strange..
EDIT 2
in this example it works, but as I pointed out on the commented line it doesn't in VS 2017
You are asking the wrong question - because it is perfectly legal what you are asking for. Could be the error is something else or you need to provide a minimal and complete example.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.