QuestionHelpLearning c++, need some help

Posts 1–13 of 13 · Page 1 of 1
Learning c++, need some help
Hi guys, I'm currently learning the basics of c++ and I need some help making an ASCII Rouglike game.

I was trying out, when some error showed which I can not understand. It would be awesome if some can tell me what's the problem.


The error:
error LNK2019: unresolved external symbol "class Level __cdecl level(void)" (?level@@YA?AVLevel@@XZ) referenced in function "public: __thiscall GameSystem::GameSystem(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0GameSystem@@QAE@V?$basic_string@DU?$char_trait s@D@std@@V?$allocator@D@2@@std@@0@Z) C:\Users\Szaby\documents\visual studio 2013\Projects\HardCore ASCRII Game\HardCore ASCRII Game\GameSystem.obj HardCore ASCRII Game

I have another error which I think is related to the first one.
Error 2: error LNK1120: 1 unresolved externals C:\Users\Szaby\documents\visual studio 2013\Projects\HardCore ASCRII Game\Debug\HardCore ASCRII Game.exe 1 1 HardCore ASCRII Game


Source:
main.cpp http://pastebin.com/6U9ad9Rh
player.cpp http://pastebin.com/9yuY5EL5
player.h http://pastebin.com/ZUX6cCv5
level.cpp http://pastebin.com/U5HEtPy9
level.h http://pastebin.com/11kyG0UB
GameSystem.cpp http://pastebin.com/h4irdq5n
GameSystem.h http://pastebin.com/EeuXYq1i

Every help/tip would be appreciated. Thank you.
If you're learning the basics of C++, you shouldn't be making games already lmao. Learn a bit more to the language first. Try using a multibyte character set in the options.
Quote Originally Posted by Jim Morrison View Post
If you're learning the basics of C++, you shouldn't be making games already lmao. Learn a bit more to the language first. Try using a multibyte character set in the options.
I'm doing this to practice. I tried the multibyte character set, but it doesn't fixed my problem
Code:
GameSystem::GameSystem(string playerName, string fileName)
{
        Player player(playerName);
        Level level();
        level().loadLevel(fileName);
}
level.loadLevel(fileName); ?
Quote Originally Posted by abuckau907 View Post
Code:
GameSystem::GameSystem(string playerName, string fileName)
{
        Player player(playerName);
        Level level();
        level().loadLevel(fileName);
}
level.loadLevel(fileName); ?
I don't get what's wrong with it.
Quote Originally Posted by pp19weapon View Post
I don't get what's wrong with it.
() usually denotes a function call:

the line "Level level();" ( @ERGaergaergaergaergearg is wrong; I think) is fine -- you're calling the constructor for level -- this is normal -- just like in the line above, where you're calling a constructor function of the player class.

For the third line, you're simply trying to refer to a member variable, so it should be the identifier followed by the dot operator
ex. myLevel.Size , myLevel.Name, myLevel.Age, etc etc..using the '.' member operator - no ()'s....() = function call
(and if you were using a pointer type, you'd use the -> operator, not the dot operator)

edit: to fix, change
Code:
 level().loadLevel(fileName); // is bad
to
Code:
 level.loadLevel(fileName); // is good
Quote Originally Posted by abuckau907 View Post
() usually denotes a function call:

the line "Level level();" ( @ERGaergaergaergaergearg is wrong; I think) is fine -- you're calling the constructor for level -- this is normal -- just like in the line above, where you're calling a constructor function of the player class.

For the third line, you're simply trying to refer to a member variable, so it should be the identifier followed by the dot operator
ex. myLevel.Size , myLevel.Name, myLevel.Age, etc etc..using the '.' member operator - no ()'s....() = function call
(and if you were using a pointer type, you'd use the -> operator, not the dot operator)

edit: to fix, change
Code:
 level().loadLevel(fileName); // is bad
to
Code:
 level.loadLevel(fileName); // is good
Yeah, pretty much what my solution is aswell.

He cannot only change
Code:
level().loadLevel(fileName);
To:
Code:
level.loadLevel(fileName);
He must remove parentheses from:

Code:
Level level();
Or else the compiler thinks that the level is gonna take arguments right?
Which it doesn't

Correct me if I am wrong please
This won't work since you have no parameter in your contructor in your "Level.h"

Code:
class Level
{
public:
	Level(); // You do not have any parameters in this contructor

	void loadLevel(string fileName);
	void printLevel();

private:
	vector<string> _levelData;
};
Then you should never put parentheses when you initialize a new Level.
Just like you did in you "GameSystem.cpp"

Code:
GameSystem::GameSystem(string playerName, string fileName)
{
    Player player(playerName);
    Level level(); // Here is parentheses
    level().loadLevel(fileName); // And here is parentheses
}
Just remove the parentheses.
This is the solution:

Code:
GameSystem::GameSystem(string playerName, string fileName)
{
    Player player(playerName);
    Level level;
    level.loadLevel(fileName);
}
Quote Originally Posted by ERGaergaergaergaergearg View Post
Yeah, pretty much what my solution is aswell.

He cannot only change
Code:
level().loadLevel(fileName);
To:
Code:
level.loadLevel(fileName);
He must remove parentheses from:

Code:
Level level();
Or else the compiler thinks that the level is gonna take arguments right?
Which it doesn't

Correct me if I am wrong please

Oops, I missed that; you're right. Well, he has to remove them both -- but you can definitely have a function that takes no arguments (the "default constructor" doesn't take any). I was thinking it was a short syntax for calling the parameterless constructor, but it isn't (because, there would be no point? Just declare it like any local variable and constructor will automatically be called..no need to ()'s - unless you're using new() and declaring it as a pointer, in which case you'd want to manually call the default constructor with "Level *level = new Level();" and then use the -> pointer member operator instead of the regular dot . member operator). I thought it was valid syntax, but isn't.


@OP I just tested the code in visualstudio2012 and apparently it actually makes the ()'s a part of the variable name :|
The IDE won't show an error(red squiggly line), but the compiler will get confused when you go to compile it.
^^this is a little weird. caused by unicode support of variable names(I miss ascii)?

fix:
Code:
GameSystem::GameSystem(string playerName, string fileName)
{
    Player player(playerName);
    Level level;
    level.loadLevel(fileName);
}
as posted by gresan6.
Thank you for everyone, I removed the parentheses and now everything is working. But I have another question, is it possible to play a song from console?
Quote Originally Posted by pp19weapon View Post
Thank you for everyone, I removed the parentheses and now everything is working. But I have another question, is it possible to play a song from console?
?????????????????????????????????????????????????? ????????????

Yes it is possible..
Quote Originally Posted by pp19weapon View Post
Thank you for everyone, I removed the parentheses and now everything is working. But I have another question, is it possible to play a song from console?
Yes, just make it output beeps.
If you want to play a song/sound and you don't mind using .WAV files, use the PlaySound() API. If you want to use any other streaming sound type, use BASS or SDL.
Posts 1–13 of 13 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?