Page 1 of 1

Implicit call on object declaration

Posted: July 14th, 2020, 7:35 am
by aspirin
Hello,

First of all, big thank you to Chili for the great C++ tutorial videos. This is my first post in the forum. Excited!
I encountered a minor issue when trying out Intermediate C++ Game Programming DirectX [Animated Sprite Character] Tutorial 12 on my own. At 8:19, I used implicit call which is Animation ani(0,0,32,48,4,surf,0.1f) instead of Animation marleRight = Animation(0,0,32,48,4,surf,0.1f). I don't get it why implicit call is not allowed here. Vistual studio indicates it expects "type specifiers" instead of parameters in parentheses when I coded "Animation ani()". Any hint is very appreciated.

Re: Implicit call on object declaration

Posted: July 14th, 2020, 1:06 pm
by albinopapa
I can't seem to find the exact reason, but it seems that you must use copy initialization or list initialization when giving default values to class members.

Initialization

Copy initialization:
Animation marleRight = Animation(0,0,32,48,4,surf,0.1f);

List initialization:
Animation marieRight = { 0, 0, 32, 48, 4, surf, 0.1f };

Re: Implicit call on object declaration

Posted: July 14th, 2020, 3:57 pm
by aspirin
OK. Thanks