我在使用带有我正在创建的自定义类的向量时遇到问题。这是我的代码
vector<image> frames;
int i = 0;
while (i < n) {
image tempImage;
tempImage.read(fullname);
frames.push_back(tempImage);
}
而 image 的构造函数就是 image() {};
我确定我错过了一些简单的东西,但我无法弄清楚它是什么。这是我的错误
/usr/include/c++/4.2.1/ext/new_allocator.h:107:20: error: no matching constructor for initialization of 'image'
{ ::new(__p) _Tp(__val); }
^ ~~~~~
/usr/include/c++/4.2.1/bits/stl_vector.h:604:20: note: in instantiation of member function
'__gnu_cxx::new_allocator<image>::construct' requested here
this->_M_impl.construct(this->_M_impl._M_finish, __x);
^
video.cpp:50:10: note: in instantiation of member function 'std::vector<image, std::allocator<image> >::push_back'
requested here
frames.push_back(tempImage);
^
./image.h:25:4: note: candidate constructor not viable: 1st argument ('const image') would lose const qualifier
image(image &img);
^
./image.h:24:4: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
image();
^
In file included from video.cpp:1:
In file included from ./video.h:6:
In file included from /usr/include/c++/4.2.1/vector:73:
/usr/include/c++/4.2.1/bits/vector.tcc:252:8: error: no matching constructor for initialization of 'image'
_Tp __x_copy = __x;
^ ~~~
/usr/include/c++/4.2.1/bits/stl_vector.h:608:4: note: in instantiation of member function 'std::vector<image,
std::allocator<image> >::_M_insert_aux' requested here
_M_insert_aux(end(), __x);
^
video.cpp:50:10: note: in instantiation of member function 'std::vector<image, std::allocator<image> >::push_back'
requested here
frames.push_back(tempImage);
^
./image.h:25:4: note: candidate constructor not viable: 1st argument ('const value_type' (aka 'const image')) would
lose const qualifier
image(image &img);
^
./image.h:24:4: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
image();
^
./image.h:26:4: note: candidate constructor not viable: requires 2 arguments, but 1 was provided
image(int rows, int columns);
^
2 errors generated.