Search code examples
c++oopinlinesymbian

Undefined symbol error when use inline methods in C++


When I make method as inline, compilation fails with this error:

Undefined symbol: 'int CPositionRequestor::State(void) const (?State@CPositionRequestor@@QBEHXZ)'

Header file:

class CPositionRequestor : public CActive
    {
    // ...

private:
    TInt iState;

public:
    inline TInt State() const;
    }

CPP file:

inline TInt CPositionRequestor::State() const
    {
    return iState;
    }

Solution

  • An inline function needs it's definition to be available in the file that is calling that function.

    So if You define it in one cpp file and try to call it in a second cpp file, then it will not be found.

    What You need to do is move this definition into the h file. (just cut & paste it after the class definition).

    Or as @einpoklum has noticed, if You don't need it, remove the inline from all the definitions.