Sign in to follow this  

New Class made -> error LNK2019: unresolved external symbol

This topic is 1864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
The unresolved symbol is Ice_Palace_City, so please show the declaration and definition of function Ice_Palace_City...

Share this post


Link to post
Share on other sites
[quote name='Black-Rook' timestamp='1355110063' post='5008967']
EDIT: Never mind, I see the problem, I shouldn't have initialized it as City Ice_Palace_City() -> But Ice_Palace_City.

Stupid mistake!
[/quote]
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");

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
This can crop up in all sorts of weird and unexpected ways:

[source]
class Point
{
public:
Point(float x, float y){ }
};

void f()
{
int x = 10, y = 16;

Point p(float(x), float(y)); // blurgh
}
[/source]

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

Share this post


Link to post
Share on other sites
[quote name='Aardvajk' timestamp='1355150382' post='5009078']
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.
[/quote]
+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?

Share this post


Link to post
Share on other sites
[quote name='wqking' timestamp='1355151723' post='5009082']
But is that standard c++ to treat point p(float(x), float(y)) as function declaration?
[/quote]
It is, unfortunately.

Share this post


Link to post
Share on other sites
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 [url=http://en.wikipedia.org/wiki/Most_vexing_parse]most vexing parse[/url].

Share this post


Link to post
Share on other sites
Sign in to follow this