Implicit call on object declaration

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
aspirin
Posts: 2
Joined: July 14th, 2020, 7:12 am

Implicit call on object declaration

Post by aspirin » July 14th, 2020, 7:35 am

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.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Implicit call on object declaration

Post by albinopapa » July 14th, 2020, 1:06 pm

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 };
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

aspirin
Posts: 2
Joined: July 14th, 2020, 7:12 am

Re: Implicit call on object declaration

Post by aspirin » July 14th, 2020, 3:57 pm

OK. Thanks

Post Reply