We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,301 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Nonstatic references

I have a class Client that is the main class for my Windows C++ application. Inside the client class, I have a number of variables and functions. One variable I'm having trouble with is the manager:

private IRManager* manager; 

The main function of my class is

int APIENTRY InnoVisitClient::_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)

and inside it, I initialize the manager:

manager = remoteClient->InitEngine(sipAccount, hWndChildVideo, hWndChildPreview);

However, in some of the other functions, I try to use the manager (i.e. manager->HangUp();), and I get the error "IntelliSense: a nonstatic member reference must be relative to a specific object".

I'm not exactly sure how to solve this, since every time I use the manager in the main function in the same way, I don't get an error.

3
Contributors
10
Replies
1 Day
Discussion Span
5 Months Ago
Last Updated
12
Views
iamthesgt
Junior Poster
119 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

can you post the code that works and the code that doesnt?

NathanOliver
Posting Virtuoso
1,516 posts since Apr 2009
Reputation Points: 281
Solved Threads: 278
Skill Endorsements: 3

That error is shown when you don't create an instance of a class and right away invoke a non-static member function of it.

Are you doing that somewhere?

theguitarist
Junior Poster in Training
79 posts since May 2011
Reputation Points: 10
Solved Threads: 4
Skill Endorsements: 0

That error is shown when you don't create an instance of a class and right away invoke a non-static member function of it.

Are you doing that somewhere?

The problem with the manager occurs in a public member function of class Client. Do I need to create an instance of the class Client inside the member function? I've never seen that.

can you post the code that works and the code that doesnt?

I posted the relevant snippets. Do you want the whole file? I don't know what you mean by "code that works and code that doesn't"

iamthesgt
Junior Poster
119 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Post the block of code where the manger is used in your main function and post the code where your manger is used in another function and it doesnt work.

NathanOliver
Posting Virtuoso
1,516 posts since Apr 2009
Reputation Points: 281
Solved Threads: 278
Skill Endorsements: 3

I get no errors here (again, in function int APIENTRY InnoVisitClient::_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)):

//set initial values through the manager
manager = remoteClient->InitEngine(sipAccount, hWndChildVideo, hWndChildPreview); 
manager->SetStunServer(strStun);
manager->OnIncommingCall = &IncomingCall; //function you can here call manager->AnswerCall() or manager->RejectCall();
manager->OnCallReleased = &CallReleased;
manager->SetSIPAccount(sipAccount);

But here, I get errors:

void Client::CommandMsgActions(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  int wmId = LOWORD(wParam);
  int wmEvent = HIWORD(wParam);

  if((HWND)lParam == hwndBtnHangUp)
  {
    if(wmEvent == BN_CLICKED)
    {
      manager->HangUp();
    }
    return;
  }
...(rest of function)
iamthesgt
Junior Poster
119 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Is mannager a member of Client or InnoVisitClient?

NathanOliver
Posting Virtuoso
1,516 posts since Apr 2009
Reputation Points: 281
Solved Threads: 278
Skill Endorsements: 3

manager is of type IRManager*, which is defined in a seperate file. The manager object is a private member variable or class Client (sorry, where it said "InnoVisitClient" above should have been simply "Client")

iamthesgt
Junior Poster
119 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

What does the IRManager class look like? What is the code for the HangUp() function?

NathanOliver
Posting Virtuoso
1,516 posts since Apr 2009
Reputation Points: 281
Solved Threads: 278
Skill Endorsements: 3

IRManager is a SIP Manager class. HangUp() just ends a call/connection.

void IRManager::HangUp()
{   
  if(currentCallConnection)
    ClearCall(currentCallConnection->GetCall().GetToken());
}

I don't think it's a problem with the function. It's declared properly, but the problem seems to be for any member of IRManager that occurs outside of the Main function:

manager->HangUp();
manager->HangUp(); //again, in a different Client function
if(!manager->isInCall())
manager->StopPreview(); //occurs multiple times in various functions
manager->StartPreview(); //occurs multiple times in various functions
manager->AnswerCall(); //occurs multiple times in various functions
manager->RejectCall(); //occurs multiple times in various functions
iamthesgt
Junior Poster
119 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

The problem with the manager occurs in a public member function of class Client. Do I need to create an instance of the class Client inside the member function? I've never seen that.

No, no. You have IRManager* manager; in your Client class. It should be fine to invoke manager's member functions.
But, in general a static member function cannot directly call a non-static member function. Like here.

And when you say "main" function, you mean Client::_tWinMain. Right?

And the error message right at that line (manager->HangUp();) ?

theguitarist
Junior Poster in Training
79 posts since May 2011
Reputation Points: 10
Solved Threads: 4
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0864 seconds using 2.73MB