Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,419 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,356 people online right now. Registration is fast and FREE... Join Now!




static function problem

 
Reply to this topicStart new topic

static function problem, error passing between classes. still need help!

Psionics
14 Oct, 2008 - 10:59 PM
Post #1

D.I.C Head
Group Icon

Joined: 6 Sep, 2008
Posts: 122



Thanked: 2 times
Dream Kudos: 100
My Contributions
I'm working on a project and I'm getting a compiler error I can't figure out:

Error 2 error LNK2001: unresolved external symbol "private: static int CCustomer::m_nNextNumber" (?m_nNextNumber@CCustomer@@0HA)

This error occurs in the file Customer.obj, and I get an unresolved linker error in file Queue.exe.

It's a linker error so I obviously need to include something differently or maybe use the keyword extern somewhere, but I can't seem to figure out how.

My static function that will return the next ticket number
cpp

// declared in my .h
static int GetNextNumber();

// definition in .cpp
int CCustomer::GetNextNumber()
{
return m_nNextNumber, m_nNextNumber++;
}

// where m_nNextNumber is
static int m_nNextNumber


and I'm adding to a Queue class such as:
cpp

void CQueue::Enqueue( const Item &item )
{
tNode *temp = new tNode( item, 0 );

// I'm not sure if this is right either
// my code is generic so Item is a typedef
temp->data.GetNextNumber();

if( !m_pHead )
m_pTail = m_pHead = temp;
else
{
m_pTail->next = temp;
m_pTail = temp;
}
++m_nSize;
}



Thanks in advance smile.gif

This post has been edited by Psionics: 14 Oct, 2008 - 11:59 PM
User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Static Function Problem
14 Oct, 2008 - 11:12 PM
Post #2

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,025



Thanked: 35 times
Dream Kudos: 125
My Contributions
From whatever you posted, even I have doubt on this temp->data.GetNextNumber();
if it's a static method, then you can't call it using any object of that class. You have to call it using classname.method style. I am not sure whether this is the reason of Linker error. but this will surely create problems for you.
User is offlineProfile CardPM
+Quote Post

Psionics
RE: Static Function Problem
14 Oct, 2008 - 11:26 PM
Post #3

D.I.C Head
Group Icon

Joined: 6 Sep, 2008
Posts: 122



Thanked: 2 times
Dream Kudos: 100
My Contributions
yea it has something to do with that, I agree.

What I'm trying to do there is set the customer's number inside of temp to the Next Number,using my static function.

What I'm playing with now is:
cpp

temp->data.SetNumber( CCustomer::GetNextNumber );

// where my SetNumber is declared as
void SetNumber( int nCustNumber );


but now I'm getting the error:

Error 1 error LNK2001: unresolved external symbol "private: static int CCustomer::m_nNextNumber" (?m_nNextNumber@CCustomer@@0HA)'


EDIT::error changed

This post has been edited by Psionics: 15 Oct, 2008 - 12:19 AM
User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Static Function Problem
14 Oct, 2008 - 11:30 PM
Post #4

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,025



Thanked: 35 times
Dream Kudos: 125
My Contributions
Try temp->data.SetNumber( CCustomer.GetNextNumber() );
You will be calling it using classname followed by dot operator followed by static method. and as it's a function the round braces are required.
User is offlineProfile CardPM
+Quote Post

Psionics
RE: Static Function Problem
14 Oct, 2008 - 11:34 PM
Post #5

D.I.C Head
Group Icon

Joined: 6 Sep, 2008
Posts: 122



Thanked: 2 times
Dream Kudos: 100
My Contributions
No that's illegal.

CCustomer is a class (obviously) and you can't use a class as an invoking object. Only a class object can be invoked (I believe), but either way that won't (and doesn't) work lol

I'm was trying to scope it in..which didn't work either, and yes I forgot the () when I typed that in there...I didn't copy and paste that, just typed it up real quick. Good call.


EDIT:: My apologies, I posted the wrong error, this is the error I get with that:
Error 1 error LNK2001: unresolved external symbol "private: static int CCustomer::m_nNextNumber" (?m_nNextNumber@CCustomer@@0HA)



I know it's kind of a touchy situation so if you'd like the project, just let me know and I'll e-mail it to you.

This post has been edited by Psionics: 15 Oct, 2008 - 12:18 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 01:05PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month