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!!
"Can't convert arguments from initilizer to Loc" Snek Game
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: "Can't convert arguments from initilizer to Loc" Snek Ga
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
Re: "Can't convert arguments from initilizer to Loc" Snek Ga
Especially since the errors are not often in the spot one would suspect it to be.
Re: "Can't convert arguments from initilizer to Loc" Snek Ga
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.
Re: "Can't convert arguments from initilizer to Loc" Snek Ga
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 ).
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.
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
Re: "Can't convert arguments from initilizer to Loc" Snek Ga
Thank you so much guys. Thank you Chilli. I have been making some progress lately.