Jump to content

  • Log In with Google      Sign In   
  • Create Account

New Class made -> error LNK2019: unresolved external symbol


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Black-Rook   Members   -  Reputation: 1563

Like
0Likes
Like

Posted 09 December 2012 - 08:28 PM

I'm getting the error:

1>main.obj : error LNK2019: unresolved external symbol "class City __cdecl Ice_Palace_City(void)" (?Ice_Palace_City@@YA?AVCity@@XZ) referenced in function _main

I cannot figure out why this is occurring.... I made the City.h file and setup all my prototypes, then made the City.cpp file to declare everything, now when I use the class I get this error.

Any reason why this is happening?

I have #include "City.h" in my main.cpp file, and City.cpp file.

What can I do to fix this? Only thing that changed since my last successful build was adding this class.
GameDev Journal: http://www.gamedev.n...-rooks-journal/

OpenChess - 1.0 done!

Classic RPG #1 - Task 9 -> January 1st 2013

Sponsor:

#2 wqking   Members   -  Reputation: 756

Like
2Likes
Like

Posted 09 December 2012 - 09:16 PM

Please show your code, especially the error related function/class.

http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.


#3 Black-Rook   Members   -  Reputation: 1563

Like
0Likes
Like

Posted 09 December 2012 - 09:27 PM

EDIT: Never mind, I see the problem, I shouldn't have initialized it as City Ice_Palace_City() -> But Ice_Palace_City.

Stupid mistake!

Edited by Black-Rook, 09 December 2012 - 09:33 PM.

GameDev Journal: http://www.gamedev.n...-rooks-journal/

OpenChess - 1.0 done!

Classic RPG #1 - Task 9 -> January 1st 2013

#4 wqking   Members   -  Reputation: 756

Like
0Likes
Like

Posted 09 December 2012 - 09:29 PM

The unresolved symbol is Ice_Palace_City, so please show the declaration and definition of function Ice_Palace_City...

http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.


#5 wqking   Members   -  Reputation: 756

Like
2Likes
Like

Posted 09 December 2012 - 09:40 PM

EDIT: Never mind, I see the problem, I shouldn't have initialized it as City Ice_Palace_City() -> But Ice_Palace_City.

Stupid mistake!

Not that stupid.
That's another C++ quirk.
When defining an object value, if using default constructor, we can't write the "()" because it will be treated as function declaration, but if not the default constructor, we have to give "()".
MyClass obj; // can't have ()
MyClass obj(1, "abc");

http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.


#6 Black-Rook   Members   -  Reputation: 1563

Like
0Likes
Like

Posted 09 December 2012 - 09:42 PM

Thanks! It is a stupid mistake for me because I made hundreds of classes, but somehow I missed this... I guess the 3 week break from programming didn't do me any good! Almost as bad as when I left only one "=" in an if statement, and couldn't find out why a function was acting up.

Oh well... Thanks!
GameDev Journal: http://www.gamedev.n...-rooks-journal/

OpenChess - 1.0 done!

Classic RPG #1 - Task 9 -> January 1st 2013

#7 bluepig.man   Members   -  Reputation: 418

Like
0Likes
Like

Posted 10 December 2012 - 05:42 AM

Oh,l thank it's a strange mistake.it;s always meet by chance.

#8 Aardvajk   Crossbones+   -  Reputation: 6218

Like
3Likes
Like

Posted 10 December 2012 - 08:39 AM

This can crop up in all sorts of weird and unexpected ways:


class Point

{

public:

    Point(float x, float y){ }

};



void f()

{

    int x = 10, y = 16;



    Point p(float(x), float(y)); // blurgh

}



That case had me scratching my head for a long time the first time I encountered it. I believe the rule is that if the compiler is able to treat it as either a declaration or a function prototype, it is required to favour the prototype interpretation of the token list.

As an aside, this particular case is another seldom quoted reason to prefer static_cast<> style casts.

Edited by Aardvajk, 10 December 2012 - 08:41 AM.


#9 wqking   Members   -  Reputation: 756

Like
0Likes
Like

Posted 10 December 2012 - 09:02 AM

That case had me scratching my head for a long time the first time I encountered it. I believe the rule is that if the compiler is able to treat it as either a declaration or a function prototype, it is required to favour the prototype interpretation of the token list.

As an aside, this particular case is another seldom quoted reason to prefer static_cast<> style casts.

+1
Very interesting example, I didn not know it before.
But is that standard c++ to treat point p(float(x), float(y)) as function declaration?

http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.


#10 Brother Bob   Moderators   -  Reputation: 8606

Like
3Likes
Like

Posted 10 December 2012 - 09:43 AM

But is that standard c++ to treat point p(float(x), float(y)) as function declaration?

It is, unfortunately.

#11 SiCrane   Moderators   -  Reputation: 9670

Like
3Likes
Like

Posted 10 December 2012 - 09:47 AM

The relevant part of the standard is section 6.8 in all of C++98, 03 and 11. For more information you can look up most vexing parse.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS