mercredi 19 avril 2017

Non-virtual public interface (NVI) with template base class - multiple symbol definitions

I have recently run into this problem when using NVI with a template base class. If I have two classes deriving from my base class with the same template argument (but differing behavior), I get a multiple symbol definition error for HandleData(), the indirection method in the base class.

Additionally marking HandleData() as inline did not change the error.

I'm grateful for any and all ideas!

Base class:

template <class DataType>
class cDataHandlerBase
{
public:
  virtual ~cDataHandlerBase();

  bool HandleData(const std::vector<DataType>& data)const
  {
    return doHandleData(data);
  }

protected:
  cDataHandlerBase();

private:
  virtual bool doHandleData(const std::vector<DataType>& data)const = 0;
};

Derived classes:

class cDataHandlerA : public cDataHandlerBase<SomeType>
{
  virtual bool doHandleData(const std::vector<DataType>& data)const override();
};

class cDataHandlerB : public cDataHandlerBase<SomeType> //same type as cDataHandlerA!
{
  virtual bool doHandleData(const std::vector<DataType>& data)const override();
};

Aucun commentaire:

Enregistrer un commentaire