سؤال

I have a class:

class SendData
{
public:
    SendData(int SendAMsg(int foo, unsigned char *bar, int length), int number)
    {
        m_nDefinePos = 0;
        m_nOtherStuffDefinedAs =0;
    }
    void somestuffhere();
    void ClearDefinition();
private:
    int aLotOfVariableshere;
    int m_nDefinePos;
};

This is the class itself. Then some stuff is called:

SendData* m_pData;
m_pData->ClearDefinition();

Which now calls this one:

void SendData::ClearDefinition()
{
    printf("Welcome to Clear Definition Script\n");
    m_nDefinePos = 0;
    // Some more stuff here
}

Here the code breaks somehow. I get the "Welcome to Clear Definition Script" message in my console, but that's all. It breaks on m_nDefinePos = 0;. (I did put in another printf command after it, never showed in the console.)

I just don't know why it breaks there and i cant find any error.

هل كانت مفيدة؟

المحلول

SendData* m_pData;
m_pData->ClearDefinition();

This declares a pointer, but doesn't create an object or initialise the pointer to point to anything, so calling a member function via the pointer will go wrong. Perhaps you wanted to create an object:

SendData data(arguments);
data.ClearDefinition();

or perhaps you wanted to initialise the pointer to point an object that already exists:

SendData* m_pData = whatever;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top