In C++ I have a header file I.h defining an abstract class (interface) with an empty
virtual destructor:
class I
{
public:
virtual ~I() {}
};
- Question 1: Is the object code for the empty destructor going to be generated in the object file of each .cpp file that includes I.h?
- Question 2: If the answer to question 1 is yes, can this be a problem (same method in different object files)?
No it will not. Methods defined inside the class definition are automatically
inline, so no need to worry about it.Note that a method being marked
inlineand actually be inlined in the binary is different.inlineis just a marker (a compiler hint at best). Especially withvirtualfunctions. Polymorphism is guaranteed to work, regardless of whether the methods are markedinlineor not.