不确定这是否是MSVC 2013终极版中的错误,但它在2015社区中运行良好。 声明:https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html
class IMetaObject;
class Context;
class Connection;
template<class Sig> class TypedSignalRelay;
template<class Sig> class TypedSignal{};
template<class...T> class MO_EXPORTS TypedSignal<void(T...)> : public ISignal
{
std::shared_ptr<Connection> Connect(ISlot* slot);
std::shared_ptr<Connection> Connect(std::shared_ptr<ISignalRelay>& relay);
std::shared_ptr<Connection> Connect(std::shared_ptr<TypedSignalRelay<void(T...)>>& relay);
};
template<class R, class...T> class MO_EXPORTS TypedSignal<R(T...)> : public ISignal
{
std::shared_ptr<Connection> Connect(ISlot* slot);
std::shared_ptr<Connection> Connect(std::shared_ptr<ISignalRelay>& relay);
std::shared_ptr<Connection> Connect(std::shared_ptr<TypedSignalRelay<R(T...)>>& relay);
};
定义: https://github.com/dtmoodie/MetaObject/blob/master/include/MetaObject/Signals/TypedSignal.hpp
-------------返回值专业化---------------------
template<class R, class...T>
std::shared_ptr<Connection> TypedSignal<R(T...)>::Connect(ISlot* slot)
{
return slot->Connect(this);
}
template<class R, class...T>
std::shared_ptr<Connection> TypedSignal<R(T...)>::Connect(std::shared_ptr<ISignalRelay>& relay)
{
...
}
template<class R, class...T>
std::shared_ptr<Connection> TypedSignal<R(T...)>::Connect(std::shared_ptr<TypedSignalRelay<R(T...)>>& relay)
{
....
}
------- void return specialization -------------
template<class...T>
std::shared_ptr<Connection> TypedSignal<void(T...)>::Connect(ISlot* slot)
{
return slot->Connect(this);
}
template<class...T>
std::shared_ptr<Connection> TypedSignal<void(T...)>::Connect(std::shared_ptr<ISignalRelay>& relay)
{
...
}
template<class...T>
std::shared_ptr<Connection> TypedSignal<void(T...)>::Connect(std::shared_ptr<TypedSignalRelay<void(T...)>>& relay)
{
...
}
2013年出现此错误,但2015年没有投诉:
4>e:\code\metaobject\include\metaobject\signals\detail/TypedSignalImpl.hpp(77): error C2244: 'mo::TypedSignal<R(T...)>::Connect' : unable to match function definition to an existing declaration
4> definition
4> 'std::shared_ptr<mo::Connection> mo::TypedSignal<R(T...)>::Connect(std::shared_ptr<mo::TypedSignalRelay<R(T...)>> &)'
4> existing declarations
4> 'std::shared_ptr<mo::Connection> mo::TypedSignal<R(T...)>::Connect(std::shared_ptr<mo::TypedSignalRelay<R(T...)>> &)'
4> 'std::shared_ptr<mo::Connection> mo::TypedSignal<R(T...)>::Connect(std::shared_ptr<mo::ISignalRelay> &)'
4> 'std::shared_ptr<mo::Connection> mo::TypedSignal<R(T...)>::Connect(mo::ISlot *)'
[已编辑]添加了完整示例和原始来源链接。