I have a constructor
A::A(const Name& n,const IRole& r)
: ...
{ }
And helper function that uses the contructor
AP<A> A::Create(const Name& n, const IRole& r)
{
return new A(n,r);
}
And g++ gives me error messages when 开发者_StackOverflowI compile this code.
error: no matching function for call to ‘AIR::AP<AIR::A>::AP(AIR::AP<AIR::A>)’
note: candidates are: AIR::AP<T>::AP(AIR::AP<U>&) [with U = AIR::A, T = AIR::A]
note: AIR::AP<T>::AP(AIR::AP<T>&) [with T = AIR::A]
note: AIR::AP<T>::AP(T*) [with T = AIR::A]
error: initializing temporary from result of ‘AIR::AP<T>::AP(T*) [with T = AIR::A]’
What's wrong with this code?
ADDED
AP<A> A::Create(const Name& n, const IRole& r)
{
AP<A> port(new A(n,r));
return port;
}
Seems to solve this issue.
You are not showing the call to Create
; is that trying to copy the result of the call into a new variable? Note that only non-const AP<T>
objects can be copied, and so temporaries (which can't bind to non-const references) are not copyable with your current definitions.
精彩评论