1,105,633 Community Members

Nonstatic references

Member Avatar
iamthesgt
Junior Poster
119 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
NathanOliver
Posting Virtuoso
1,657 posts since Apr 2009
Reputation Points: 284 [?]
Q&As Helped to Solve: 310 [?]
Skill Endorsements: 4 [?]
 
0
 

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

Member Avatar
theguitarist
Junior Poster in Training
96 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
iamthesgt
Junior Poster
119 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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"

Member Avatar
NathanOliver
Posting Virtuoso
1,657 posts since Apr 2009
Reputation Points: 284 [?]
Q&As Helped to Solve: 310 [?]
Skill Endorsements: 4 [?]
 
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.

Member Avatar
iamthesgt
Junior Poster
119 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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)
Member Avatar
NathanOliver
Posting Virtuoso
1,657 posts since Apr 2009
Reputation Points: 284 [?]
Q&As Helped to Solve: 310 [?]
Skill Endorsements: 4 [?]
 
0
 

Is mannager a member of Client or InnoVisitClient?

Member Avatar
iamthesgt
Junior Poster
119 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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")

Member Avatar
NathanOliver
Posting Virtuoso
1,657 posts since Apr 2009
Reputation Points: 284 [?]
Q&As Helped to Solve: 310 [?]
Skill Endorsements: 4 [?]
 
0
 

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

Member Avatar
iamthesgt
Junior Poster
119 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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
Member Avatar
theguitarist
Junior Poster in Training
96 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
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();) ?

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article