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(vo id)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
class PA_node {
private:
bool conflict_removed;
public:
bool conflict_already_removed()
};
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_
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_
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
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.