Link to home
Start Free TrialLog in
Avatar of gurry_uor
gurry_uor

asked on

Inline functions not linking successfully

I am writing the following code in MS Visual C++ version 6.0:

class PA_node {
private:
     bool conflict_removed;
public:
     bool conflict_already_removed() const;
};


And the implementation is (it is of course not placed in the same .h file as the class declaration but in a separate .cpp file):

inline bool PA_node::conflict_already_removed() const {
      return conflict_removed;
}



Please note the "inline" prefix in the function defintion. Now my problem is that when I try to link this code the linker complains that it can't find the function definition:

error LNK2001: unresolved external symbol "public: bool __thiscall PA_node::conflict_already_removed(void)const " (?conflict_already_removed@PA_node@@QBE_NXZ)


What puzzles me is that the code looks perfectly okay and also, when I remove the "inline" prefix it links without hitch. Also, the linker is linking some other "inlined" functions without problem and it is complaining about others and to me this sounds very random. What is going wrong here? Or is it just a bug in MS Visual C++.

Please help
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gurry_uor
gurry_uor

ASKER

I tried that and it works. But I still, some other member functions of the same class which are placed in separate .cpp file and are "inlined" are linking perfectly. Only this particular one wasn't. What does that mean? Is it that the compiler is not actually inlining the other functions (since the compiler has the option of ignoring the 'inline' keyword)?

Secondly, if one is always required to place 'inlined' functions in the header file itself, most people would never use the 'inline' keyword because this will force them to place their member function implementations in header file and that would mean they are revealing their implementation to everyone, which most people don't want. So how does it work?

Thanks for your answer.
Oh I get it. The other functions which are linking succefully haven't been called anywhere yet. I am sorry for my stupid second question. So thanks Alex. I accept your answer.