Page 2 of 2

Re: Snekgame unresolved externals

Posted: March 28th, 2017, 5:18 pm
by misterchi
Hi,

I added the code.

Thanks!

Re: Snekgame unresolved externals

Posted: March 29th, 2017, 5:44 pm
by misterchi
Hi Chili,

I added the snek. Thx!

Re: Snekgame unresolved externals

Posted: March 29th, 2017, 6:31 pm
by albinopapa
Snek Tutorial 14a at 28 min 55 sec

At this point in the video chili creates the definitions for the functions you are missing.

Unresolved externals usually means that the compiler can't find a variable or function that is being used or called. In this case, it's all the Snake::Segment functions that you did not define. You have them declared, but not defined and the Snake functions call some of them like Snake::Segment::MoveBy and Snake::Segment::Segment. Which means the compiler is being asked to use some code that it can't find, and it is telling you that you must be crazy.

Finish the video and define all the rest of the functions and see if that helps.

Re: Snekgame unresolved externals

Posted: March 29th, 2017, 6:43 pm
by albinopapa
Oh, just found another issue you were having is the Snake::Snake having issues with missing Snake::Segment::Segment. It's because you added a constructor to Location ( which chili did not add ). Since you added a constructor, the compiler doesn't implicitly add the default constructor to Location. Which means Snake::Segment::Location loc needs to be initialized using a Snake::Segment::Segment constructor.

You have a few options:
Delete the constructor you made from Location
Add a default constructor to Location ( Location() = default; )
Add a constructor to Segment that initializes Snake::Segment::Location loc

Re: Snekgame unresolved externals

Posted: March 29th, 2017, 7:09 pm
by albinopapa
Hopefully the version you downloaded has the SpriteCodex.h and SpriteCodex.cpp files, because the one you posted does not.

Re: Snekgame unresolved externals

Posted: March 30th, 2017, 12:28 pm
by misterchi
Tanks Albinopapa,I deleted the constructor for location. Now it works fine. But I still have a question:
I dont understand why this: "Location loc = { x,y };" works because how does Visual Studio know which variables I want to change in loc object?

Re: Snekgame unresolved externals

Posted: March 30th, 2017, 1:05 pm
by albinopapa
Well, the {x,y} creates a temporary Location by storing each variable consecutively in memory, then assigns that data to Location loc. So if you had done Location loc = {y, x} loc.x would have been what your y was and loc.y would have been what your x was when you passed them in.

Re: Snekgame unresolved externals

Posted: March 30th, 2017, 8:03 pm
by misterchi
Cool, maybe it's a stupid question, but how does the computer know that when I write Location loc = {x,y}; I want the x to be stored in loc.x and not in loc.y or in any other variable?

misterchi

Re: Snekgame unresolved externals

Posted: March 30th, 2017, 8:19 pm
by LuisR14
it's done according to the order in which you declare the variables in the class/struct :)

Re: Snekgame unresolved externals

Posted: March 30th, 2017, 10:56 pm
by albinopapa
misterchi wrote:Cool, maybe it's a stupid question, but how does the computer know that when I write Location loc = {x,y}; I want the x to be stored in loc.x and not in loc.y or in any other variable?

misterchi
Yeah, I kind of explained that already.