我有一个类,其中包含一个由std::vector<std::vector<T> >
. 在参数化构造函数中,我使用了移动语义。当我创建此类的对象时,我收到与constructor
. 是否有人知道初始化是否使用移动语义正确完成?还是它实际上与它vector<vector>
本身有关?
template < class T, class L = size_t >
class Foo{
public:
...
Foo(std::vector<L> , std::vector<std::vector<T> > );
...
private:
...
std::vector<L> shape_;
std::vector<std::vector<T> > cost_;
...
};
template < class T, class L >
Foo<T,L>::Foo( std::vector<L> shape, std::vector< std::vector< T > > ucosts )
:shape_(std::move(shape)), cost_(std::move(ucosts))
{
}
这是我初始化对象的方式:
typedef double termType;
typedef Foo<termType, int> myFoo;
std::vector<int> ushape(10);
std::vector< std::vector< termType> > ucosts(2, std::vector<termType> ( 5, 0 ) );
myFoo ff1(ushape, ucosts); // <------ DOES NOT WORK
Foo<termType, int> ff2(ushape, ucosts); // <------ DOES WORK
编译器消息错误是:`error C2664:
'Foo<T,L>::Foo(std::vector<_Ty>,std::vector<std::vector<double>>)' : cannot convert
parameter 2 from 'std::vector<_Ty>' to 'std::vector<_Ty>'
1> with
1> [
1> T=termType,
1> L=int,
1> _Ty=int
1> ]
1> and
1> [
1> _Ty=std::vector<float>
1> ]
1> and
1> [
1> _Ty=std::vector<double>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called