我有一個使用向量與我創建的自定義類的問題。這裏是我的代碼問題與向量和自定義類在c + +微不足道的構造函數
vector<image> frames;
int i = 0;
while (i < n) {
image tempImage;
tempImage.read(fullname);
frames.push_back(tempImage);
}
而圖像的構造函數只是圖像(){};
我相信我失去了一些東西簡單,但我無法弄清楚它是什麼。這裏是我的錯誤
/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.
必須是圖像類中的拼寫錯誤。你能否分享它的聲明? –