У меня есть следующий код:Почему shared_ptr <T> ожидает конструктор копирования/перемещения в T?
#include <memory>
using namespace std;
template<typename U> class A;
template<typename U>
class B
{
private:
shared_ptr<const A<U>> _a;
public:
B (shared_ptr<const A<U>> __a) {
_a = __a;
}
};
template<typename U>
class A
{
public:
B<U> foo() const {
return { make_shared<const A<U>> (this) };
}
};
int
main()
{
A<int> a;
B<int> b = a.foo();
return 0;
}
G ++ 4.8.0 и Clang 3.3svn сообщают, что класс A
не имеет копию или переместить конструктор. Для например, G ++ напечатать следующее сообщение:
/home/alessio/Programmi/GCC/include/c++/4.8.0/ext/new_allocator.h:120:4: error: no matching function for call to ‘A<int>::A(const A<int>* const)’
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
^
/home/alessio/Programmi/GCC/include/c++/4.8.0/ext/new_allocator.h:120:4: note: candidates are:
prova.cpp:19:7: note: constexpr A<int>::A()
class A
^
prova.cpp:19:7: note: candidate expects 0 arguments, 1 provided
prova.cpp:19:7: note: constexpr A<int>::A(const A<int>&)
prova.cpp:19:7: note: no known conversion for argument 1 from ‘const A<int>* const’ to ‘const A<int>&’
prova.cpp:19:7: note: constexpr A<int>::A(A<int>&&)
prova.cpp:19:7: note: no known conversion for argument 1 from ‘const A<int>* const’ to ‘A<int>&&’
В чем причина?
'A' не является классом. Это шаблон. –