0

構築しようとしているスクリプトに次のコードがあります。

typedef std::vector< typename Sphere::vec_type > VV; 
typedef typename Sphere::vec_type vec_type; 
VV v( count , s.dimension() ); 
for ( int ii=0; ii<count; ++ii ) { 
v[ii] = randomPointOnSurface( s ); 

次のエラーが発生します。

error: no matching function for call to 'std::vector<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >::_M_fill_initialize(size_t, int&)'
/usr/include/c++/4.4/bits/stl_vector.h:1033: note: candidates are: void std::vector<_Tp, _Alloc>::_M_fill_initialize(size_t, const _Tp&) [with _Tp = std::vector<float, std::allocator<float> >, _Alloc = std::allocator<std::vector<float, std::allocator<float> > >]

回避策は s.dimension() を削除することですが、これを修正できる他の方法はありますか?

4

1 に答える 1

2

ネストされたベクトルがあるため、次のようなものが必要です

VV v( count , vec_type(s.dimension()) ); 

これにより、各count内部ベクトルが size を持つように初期化されs.dimension()ます。

于 2013-07-14T15:03:52.790 に答える