jeudi 17 décembre 2015

C++: compiler warning C4505 when including header of class derived from class template

I have the following hierarchy of classes:

class FilterMktData
{
   virtual std::vector<std::string> filter(std::vector<std::string>) = 0;
   ...
}

class FilterMktDataDecorator : public FilterMktData
{
   virtual std::vector<std::string> filter(std::vector<std::string>);
   ...
}

template<typename T>
class FilterBy : public FilterMktDataDecorator
{
   std::vector<std::string> filter(std::vector<std::string>);
   ...
}

class FilterByVolume : public FilterBy<int>
{
   ...
}

I'm using the decorator pattern. FilterMktData is the interface, FilterMktDataDecorator is the class that provides an implementation of the interface that delegates the actual work to an inner shared pointer to FilterMktData. This pointer is passed to the constructor.

Now, the class template FilterBy implements the filter method by using a lambda expression passed to the constructor (I'm using an argument of type std::function<bool(T)>). The idea is to filter the elements that when evaluated return true. It was necessary to introduce the template because the elements are std::strings and have to be converted before passing them to the lambda expression, and can be anything.

Finally FilterByVolume passes a lambda expression to the constructor of FilterBy<int> that returns true if the volume is less than a certain value.

I have tested the behavior of the classes and they work as expected. The only problem is that I get the following compiler warning

FilterBy.h(51): warning C4505: 'FilterBy<int>::filter' : unreferenced local function has been removed

only when including in my main.cpp the header file for FilterByVolume and not when I include the one for FilterBy, even if my main does not instantiate any object of the above classes.

Question: how do I get rid of the warning?

Thanks for any help.

Aucun commentaire:

Enregistrer un commentaire