私は、とりわけ、からなる属性を持つクラスを持っていますstd::vector<std::vector<T> >
。パラメーター化されたコンストラクターでは、移動セマンティクスを使用しています。このクラスのオブジェクトを作成すると、constructor
. move-semantics を使用して初期化が適切に行われたかどうかは誰にもわかりませんか? それとも、それは実際に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
コンパイラ メッセージ エラーは次のとおりです。
'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