"Can't convert arguments from initilizer to Loc" Snek Game

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
sheriff40
Posts: 7
Joined: August 19th, 2017, 10:21 am

"Can't convert arguments from initilizer to Loc" Snek Game

Post by sheriff40 » August 19th, 2017, 11:33 am

I made the snake constructor like:
Snake::Snake(Loc& loc)
{
segments[0].Inithead(loc);
}
Then i made the object:
Snake Snek;
Now, when i want to initilize the loc i get error like:
Snek({2,2});
Cannot convert arguments from initilizer to Loc

But when I remove the reference from the defination like:
Snake::Snake(Loc loc) //No reference to loc//
{
segments[0].Inithead(loc);
}
No error is shown. What is happening here. Please help!!

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

Re: "Can't convert arguments from initilizer to Loc" Snek Ga

Post by albinopapa » August 19th, 2017, 2:52 pm

You should share source code not just snippets when asking for help.
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

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: "Can't convert arguments from initilizer to Loc" Snek Ga

Post by Zedtho » August 19th, 2017, 3:12 pm

Especially since the errors are not often in the spot one would suspect it to be.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: "Can't convert arguments from initilizer to Loc" Snek Ga

Post by chili » August 20th, 2017, 3:19 pm

try const Loc& loc

http://ideone.com/u8LwMY
Chili

reductor
Posts: 49
Joined: October 24th, 2016, 12:23 pm

Re: "Can't convert arguments from initilizer to Loc" Snek Ga

Post by reductor » August 21st, 2017, 11:26 pm

The reason for this is that it is unable to determine a type, your attempting to construct a temporary, which can not be treated as a non-const reference, unfortunately MSVC is terrible for giving good error messages. Likely if you added the type before {} it would better hint at the issue.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: "Can't convert arguments from initilizer to Loc" Snek Ga

Post by chili » August 22nd, 2017, 1:12 am

Yeah, definitely much better diagnostics from gcc here. It could be worse, it could just allow you to pass a temporary by reference (which is someting MSVC permitted in previous versions I believe :lol:).

This just demonstrates another reason to const your reference parameters whenever possible: it gives you more flexibility regarding what you can pass in vs. non-const reference semantics.
Chili

sheriff40
Posts: 7
Joined: August 19th, 2017, 10:21 am

Re: "Can't convert arguments from initilizer to Loc" Snek Ga

Post by sheriff40 » August 27th, 2017, 3:09 pm

Thank you so much guys. Thank you Chilli. I have been making some progress lately.

Post Reply