Reputation: 153
I have a inline operator overloading in cpp file. My understanding is the inline function should also put in the header file with the body of function.
but when i do that. the error come out which is redefinition of "operator =="
could you explain why is the error like that. and also, could anyone explain what sorts of content should keep in the header file.?
inline bool operator ==(Duration& d1, Duration& d2)
{
return d1.getSecond() == d2.getSecond();
}
Upvotes: 0
Views: 132
Reputation: 308186
Inline functions need to go in the header, not the source. Otherwise they won't be available in the other sources where you try to call them.
Having a second copy in the source is indeed a duplicate.
Upvotes: 2
Reputation: 9161
You can't define a function twice. Declare it in the header and define it in the cpp - OR - just define it in the header and leave it out of the cpp completely.
Upvotes: 3