I have a compile error in the following code. It seems that the compiler interprets class method set as a template which - at first glance - is completely unrelated to my code.
#include <cassert>
#include <limits>
using namespace std;
template <class T>
class ReduceScalar{
public:
T get() { return *r; };
void set(T t) { *r = t; };
void set(T* t) { r = t; };
private:
T* r;
};
template <class T>
class ReduceSum : public ReduceScalar<T>
{
public:
ReduceSum(T* target) { set(target); set(0); } // COMPILE ERROR
};
Compiler gives the following error:
../test/../io/scalarreducers.h:34:26: error: use of class template 'set' requires template arguments
ReduceSum(T* target) { set(target); set(0); }
But I think it's because it thinks that set is a template:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__tree:685:71: note: template is declared here
template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY set;
I do not understand why the compiler tries to instantiate that template for method set and not just call method set. How can I resolve this name confusion?
using namespace std;somewhere this code is included?this->set(target);.std::setusing namespace std;. The base class is dependent, so it's not searched unless you dothis->set.