tags:

views:

50

answers:

3

I have this function definition inside my cpp file;

    LRESULT CRebarHandler::onSetRedraw(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 
    {
     bHandled=false;
     if (m_ieVer==6){
      if (!m_hWndToolbar)
      scanForToolbarSlow();
     }
    return S_OK;
   }

My problem is I don't know how to call it from another function inside the same file. I want to call it from this function:

 void CRebarHandler::setButtonMenu2(){
 bool b=false;
 onSetRedraw(0,0,0,false);   <------ is this the correct way?
}

Must I provide all the 4 values? Can I just send no value?

Help me..

A: 

It all depends on the function prototype, if there is an overload with default params, you dont need to provide values from within the function. If there isnt, you'll need all four parameters.

Since both methods seem to be in the same class, the method that you show * should * work.

Ryan Rohrer
+1  A: 

Yes, the way you have things defined you must provide values for all the parameters. Additionally, that last parameter must be a variable, because you defined it to be passed by reference.

If there are situations where that seems kind of silly and you'd just like it to fill in all 0's and false for you, you can supply the definition with those values as defaults, like so:

LRESULT CRebarHandler::onSetRedraw(UINT uMsg=0, WPARAM wParam=0, LPARAM lParam=0, BOOL& bHandled)  
    { 

(note: You can't supply a default for bHandled, as it is passed by reference. That's an indication that your routine wants to modify it, and thus is must be a modifiable variable).

Then you can call it like this:

onSetRedraw(false)

Another option would be to just make another copy of the routine without any of those parameters. If you want you could make it private, so that only members of the class itself can call it.

T.E.D.
A: 

No, the last parameter is a reference value so you need to provide a variable instead of a value (to be slightly more accurate, you need to provide an lvalue instead of an rvalue):

void CRebarHandler::setButtonMenu2(){
  bool b=false;
  onSetRedraw(0,0,0,b);   // note the change here
}

As your example stands, you must provide all the arguments. But it's possible to provide default arguments so that you don't have to. That said, the rules of C++ require you to provide default arguments for the last parameters before the first values. Since a reference must be initialized with a variable/lvalue, it would be awkward to do this.

R Samuel Klatchko