In header view.h:
template<class S, template<typename> class V>
void Operate(S c, const V<S>& vx);
template<class T, template<typename> class U>
class ViewBase
{
template<class S, template<typename> class V>
friend void Operate(S c, const V<S>& vx);
};
template<class T>
class ViewTypeA : public ViewBase<T, ViewTypeA>
{
};
template<class T>
class ViewTypeB : public ViewBase<T, ViewTypeB>
{
};
template<class S, template<typename> class V>
void Operate(S c, const V<S>& vx)
{
}
In cpp:
#include "view.h"
int main(int argc, char **argv)
{
Operate(5, ViewTypeA<int>());
Operate(5, ViewTypeB<int>());
}
gcc (compiling with -std=gnu++11) gives errors:
Build: Debug in codeblocks (compiler: GNU GCC Compiler) main.cpp||In function ‘int main(int, char**)’: main.cpp|7|error: call of overloaded ‘Operate(int, ViewTypeA&)’ is ambiguous main.cpp|7|note: candidates are: view.h|25|note: void Operate(S, const V&) [with S = int; V = ViewTypeA] view.h|9|note: void Operate(S, const V&) [with S = int; V = ViewTypeA; T = int; U = ViewTypeA]
main.cpp|8|error: call of overloaded ‘Operate(int, ViewTypeB)’ is ambiguous main.cpp|8|note: candidates are: view.h|25|note: void Operate(S, const V&) [with S = int; V = ViewTypeB] view.h|9|note: void Operate(S, const V&) [with S = int; V = ViewTypeB; T = int; U = ViewTypeA]
Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Question:
The class template parameters should not come into the picture at all - am I right? The ambiguity seems to be based on the template parameters of the class.