我从Visual Studio移植到Xcode的库使用模板链。我的链在Visual Studio中正常工作。但是,当我使用Apple LLVM 6.0在Xcode中编译它时,我收到错误
References to overloaded function could not be resolved; did you mean to call it?
更新
我创建了一个独立的示例,它在Visual Studio中编译但无法在Xcode中编译,但我在库中看到的错误相同。
注意:我可以通过其他方式修复我的库代码。但是,我想借此机会让某人教我一些关于消歧的新内容以及编译器之间的差异。这种模式不标准吗?它是否只能在Visual Studio中使用,因为语言扩展?
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;
}
感谢您的帮助。
更新2 :我更改了一些名称以使其更有用,并重新构建代码以清楚问题所在。我还在错误之前放置了一些示例代码,以显示错误未出现的情况。