what does "error : a nonstatic member reference must be relative to a specific object" mean?

Oscar Yuandinata picture Oscar Yuandinata · Mar 22, 2012 · Viewed 196.4k times · Source
int CPMSifDlg::EncodeAndSend(char *firstName, char *lastName, char *roomNumber, char *userId, char *userFirstName, char *userLastName)
{
    ...

    return 1;
}

extern "C"
{
    __declspec(dllexport) int start(char *firstName, char *lastName, char *roomNumber, char *userId, char *userFirstName, char *userLastName)
    {
        return CPMSifDlg::EncodeAndSend(firstName, lastName, roomNumber, userId, userFirstName, userLastName);
    }
}

On line return CPMSifDlg::EncodeAndSend I have an error : Error : a nonstatic member reference must be relative to a specific object.

What does it mean?

Answer

Nawaz picture Nawaz · Mar 22, 2012

EncodeAndSend is not a static function, which means it can be called on an instance of the class CPMSifDlg. You cannot write this:

 CPMSifDlg::EncodeAndSend(/*...*/);  //wrong - EncodeAndSend is not static

It should rather be called as:

 CPMSifDlg dlg; //create instance, assuming it has default constructor!
 dlg.EncodeAndSend(/*...*/);   //correct