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.

Recommended Answers

All 10 Replies

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

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?

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"

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.

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)

Is mannager a member of Client or InnoVisitClient?

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

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

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

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();) ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.