tags:

views:

49

answers:

1
void CVisualStudioDemoDoc::updateLine(void)
{
int newln = GetLineNumber(p_buf);
reinterpret_cast<CVisualStudioDemoView *>(m_viewList.GetHead())->SetCurrentLineNumber(ln, newln);
ln = newln;
}

I want to call this function from another part of my code without having to give the object pointer and include headers.

I want to call it just like a normal void function.

    if (changementLigne == true) {
        currentLine = prog;
        // TODO : appeler le callback de X2
        updateLine();
        Suspendre();
        changementLigne = false;
    }

I dont know if it's possible, since the CVisualStudioDemoDoc class is an MFC class, I didn't find a pointer I can use.

+3  A: 

You can't do this.

If a member function refers to member variables, it needs a valid this pointer. If you don't include the header file that declares the function, the compiler can't know what you're referring to. How can it know that updateLine() is a function unless you tell it?

If you're trying to call a C++ member function from C code then you need to write a wrapper. Something like the following (not tested):

.h file:

extern "C" {
CallUpdateLine(void* data);
}

.cpp file:

extern "C" {
  CallUpdateLine(void* data)
  {
    CVisualStudioDemoDoc* ptr = static_cast<CVisualStudioDemoDoc*>(data);
    ptr->updateLine();
  }
}

There are other questions that might be helpful as well.

Bill
Well looks we thought of the same thing, I got it working using a wrapper function too. Problem solved IMO.
toto