codekiddy
codekiddy

Reputation: 6137

Intellisense warning: Incomplete type is not allowed (in inline method but defintion of type is in cpp)

I've forward declared my enum class, definition is in cpp, program compiles but I'm getting a red "wave" under the type name (below in inline method)

I would like to ask if it's recomended to move that inlined method into cpp file? I'm a hoby programer so I don't know whether is this inlined method with incomplete type in a header file ok or not.

header file:

#include <map>

using std::map;
enum class MinimumName;

    class Limits
    {
    public:
        Limits(TableLayout layout);
        void SetMinimum(MinimumName name, unsigned int minimum);

// other stuff irrelevant

    private:
        typedef map<MinimumName, unsigned int> MinContainer;
MinContainer::iterator Miniter;
        MinContainer Minimums;
};
                                   //intelisence warning here in argument list
inline void Limits::SetMinimum(MinimumName name, unsigned int minimum)
{                             // incomplete type is not allowed
    Miniter = Minimums.find(name);
    Miniter->second = minimum;
}

cpp file

enum class MinimumName
{
    Inside,
    Outside,
    Table
};

shall I move it into cpp file or not? and why?

Upvotes: 2

Views: 4094

Answers (1)

iammilind
iammilind

Reputation: 69988

If a class method (or for that matter any function) has to be put in a header file which is going to be included by several .cpp files then it has to be inline.

This inline does not necessarily mean the usual macro style inlining. The macro style inlining is decided by compiler and the programmer doesn't have much control over it.
This inline keyword is the guaranteed effect where only one definition is generated for all the .cpp file. Effectively the inline keyword maintains the ODR.

AFAIK, conventionally a method has to be made inline (for ODR purpose) when it's declared inside the class. So once you make the method inline inside the class everything should work fine without error/warning. Later on putting inline keyword for method definition outside the class is redundant.

Upvotes: 2

Related Questions