A library that I'm porting from Visual Studio to Xcode uses a template chain. My chain works correctly in Visual Studio. However, when I compile it in Xcode using Apple LLVM 6.0, I get the error
References to overloaded function could not be resolved; did you mean to call it?
Update
I've created a standalone example that compiles in Visual Studio but fails to compile in Xcode with the same error that I'm seeing in my library.
Note: I can probably fix my library code by other means. However, I'd like to take this opportunity for someone to teach me something new about disambiguation and the differences between the compilers. Is this pattern non-standard? Did it only work in Visual Studio because of a language extension?
class Test1{};
class Test2{};
struct NullType{};
template< class T, int id>
class SpecialHandler
{
public:
enum { ETypeId = id };
void handlerFunc( float, int ){}
};
template<typename TReturn, class TObj, typename TParam1, typename TParam2>
class TestResolveClass
{
public:
template< TReturn (TObj::*Func)(TParam1, TParam2 ) >
inline static void funcThatFailsResolve(TObj* obj)
{
(void)obj;
(void)Func;
}
};
template< class TSpecialHandler, class TParent >
class Chain :
public TParent
{
public:
typedef TParent Parent;
typedef TestResolveClass<void, SpecialHandler<Test1, 1>, float, int> TestResolver1;
typedef TestResolveClass<void, SpecialHandler<Test2, 2>, float, int> TestResolver2;
typedef TestResolveClass< void, TSpecialHandler, float, int > TemplatedTestResolver;
void traverseChain()
{
Parent* parentPtr = static_cast<Parent*>( this );
parentPtr->traverseChain(); // up the chain we go
SpecialHandler<Test1, 1> testaroo;
TestResolver1::funcThatFailsResolve< &SpecialHandler<Test1, 1>::handlerFunc >( &testaroo ); // no error
TemplatedTestResolver::funcThatFailsResolve< //<-- Reference to overloaded function could not be resolved; did you mean to call it?
&TSpecialHandler::handlerFunc
>( &m_handler );
TemplatedTestResolver::funcThatFailsResolve< // <-- Reference to overloaded function could not be resolved; did you mean to call it?
static_cast<void (TSpecialHandler::*)( float, int )>( &TSpecialHandler::handlerFunc )
>( &m_handler );
}
private:
TSpecialHandler m_handler;
};
template<>
class Chain< NullType, NullType >
{
public:
void traverseChain(){}
};
typedef Chain< NullType, NullType > ChainLink0;
typedef Chain< SpecialHandler<Test1, 1>, ChainLink0 > ChainLink1;
typedef Chain< SpecialHandler<Test2, 2>, ChainLink1 > ChainLink2;
typedef ChainLink2 FullChain;
class ChainContainer :
public FullChain
{
public:
ChainContainer()
{
traverseChain();
}
};
int main()
{
ChainContainer test;
(void)test;
}
Thanks for your help.
Update 2: I changed a few of the names to be more useful and restructured the code to be clear where the problem is. I also placed some example code before the error to show a situation in which the error does not appear.