Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > error LNK2001: unresolved external symbol

Reply
Thread Tools

error LNK2001: unresolved external symbol

 
 
Ed Dana
Guest
Posts: n/a
 
      01-05-2007
Greetings, all.

I'm familiar with other object oriented programming tools, such as Java
& REBOL. In an effort to become more familiar with C++, I decided to
write an object oriented BlackJack program. To begin with, I needed some
simple static routines for telling the value or suite of a face card.
So, I wrote the following C++ routine for Suites:
================================================== ====================
class Suite {
public:
static int getSuiteID(int prmCardID);
static char *getSuiteName(int prmCardID);
static char getShortName(int prmCardID);
static int main( );

Suite();

private:
static char *clsSuiteName[];
static int getSID(int prmCardID);

};

Suite::Suite( ) {
clsSuiteName[0] = "Hearts";
clsSuiteName[1] = "Clubs";
clsSuiteName[2] = "Diamonds";
clsSuiteName[3] = "Spades";
}

int Suite::getSID(int prmCardID) {
return prmCardID / 13;
}

int Suite::getSuiteID(int prmCardID) {
return getSID(prmCardID) + 1;
}

char *Suite::getSuiteName(int prmCardID) {
return clsSuiteName[ getSID( prmCardID ) ];
}

char Suite::getShortName(int prmCardID) {
return (char)getSuiteName(prmCardID);
}
================================================== ====================

Compiling this in M$ VC gives me the linker error: 'Suite.obj : error
LNK2001: unresolved external symbol "private: static char * *
Suite::clsSuiteName" (?clsSuiteName@Suite@@0PAPADA)'

Compiling it in wxDevC++ gives me a similar error: "[Linker error]
undefined reference to `Suite::clsSuiteName'"

I've tried everything I can think of to correct the problem, but at this
point, I ain't got a clue.

Any and all advice is welcome.

Ed.
 
Reply With Quote
 
 
 
 
Michael
Guest
Posts: n/a
 
      01-05-2007
> class Suite {
<snip>
> private:
> static char *clsSuiteName[];
> };
>

<snip>

> ================================================== ====================
>
> Compiling this in M$ VC gives me the linker error: 'Suite.obj : error
> LNK2001: unresolved external symbol "private: static char * *
> Suite::clsSuiteName" (?clsSuiteName@Suite@@0PAPADA)'
>
> Compiling it in wxDevC++ gives me a similar error: "[Linker error]
> undefined reference to `Suite::clsSuiteName'"


You need to define clsSuiteName. You've declated it in your class (in
a .h file or some such), now you need to define it in a .cpp file or
some such. The definition will probably look something like this:
char* Suite::clsSuiteName[] = { "abc", "def" };

Michael

P.S. While you're at it, you might look into the joy of std::string
instead of char*, but that's orthogonal to the problem you're having.

 
Reply With Quote
 
 
 
 
Jim Langston
Guest
Posts: n/a
 
      01-05-2007
"Ed Dana" <(E-Mail Removed)> wrote in message
news:Xgxnh.10686$(E-Mail Removed)...
> Greetings, all.
>
> I'm familiar with other object oriented programming tools, such as Java &
> REBOL. In an effort to become more familiar with C++, I decided to write
> an object oriented BlackJack program. To begin with, I needed some simple
> static routines for telling the value or suite of a face card. So, I wrote
> the following C++ routine for Suites:
> ================================================== ====================
> class Suite {
> public:
> static int getSuiteID(int prmCardID);
> static char *getSuiteName(int prmCardID);
> static char getShortName(int prmCardID);
> static int main( );
>
> Suite();
>
> private:
> static char *clsSuiteName[];


You declared clsSuitName, but you have to define it.

> static int getSID(int prmCardID);
>
> };


char* Suit::clsSuitName[] = { "Hearts", "Clubs", "Diamands", "Spades" };

> Suite::Suite( ) {
> clsSuiteName[0] = "Hearts";
> clsSuiteName[1] = "Clubs";
> clsSuiteName[2] = "Diamonds";
> clsSuiteName[3] = "Spades";
> }


I think this is what you tried to do for clsSuitName, but you misnamed it,
and made it a function.

> int Suite::getSID(int prmCardID) {
> return prmCardID / 13;
> }
>
> int Suite::getSuiteID(int prmCardID) {
> return getSID(prmCardID) + 1;
> }
>
> char *Suite::getSuiteName(int prmCardID) {
> return clsSuiteName[ getSID( prmCardID ) ];
> }
>
> char Suite::getShortName(int prmCardID) {
> return (char)getSuiteName(prmCardID);
> }
> ================================================== ====================
>
> Compiling this in M$ VC gives me the linker error: 'Suite.obj : error
> LNK2001: unresolved external symbol "private: static char * *
> Suite::clsSuiteName" (?clsSuiteName@Suite@@0PAPADA)'
>
> Compiling it in wxDevC++ gives me a similar error: "[Linker error]
> undefined reference to `Suite::clsSuiteName'"
>
> I've tried everything I can think of to correct the problem, but at this
> point, I ain't got a clue.
>
> Any and all advice is welcome.
>
> Ed.



 
Reply With Quote
 
Ed Dana
Guest
Posts: n/a
 
      01-05-2007
@ All

Excellent, thank you! I knew I was missing something obvious.


@ Michael

> P.S. While you're at it, you might look into the joy of std::string
> instead of char*, but that's orthogonal to the problem you're having.


I did, initially, but that caused me more errors, so I decided I should
learn to crawl before I walk.

Ed.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is Error 1 error LNK2019: unresolved external symbol ???? Trent C++ 9 06-29-2007 08:32 PM
unresolved external symbol/using an external dll Scott Allen C++ 8 05-02-2004 06:11 PM
"unresolved external symbol" error in MSVC++ 6.0 Rodolphe C++ 4 10-03-2003 09:44 AM
error LNK2001: unresolved external symbol _IID_IDirectDraw7 Izak Pretorius C++ 2 09-14-2003 11:18 AM
Re: unresolved external symbol error. Need help! John Harrison C++ 0 07-20-2003 07:18 PM



Advertisments