Nested vector initialization problem
Hello,
I initialized a nested vector with the following code as:
Code:
vector<vector<Point> > vectorB(4, vector<Point> (int(vectorA.size()), 0));
And came across the following error during link stage:
"/usr/include/c++/4.6/bits/stl_vector.h:1080:4: error: no matching function for call to ‘std::vector<cv::Point_<int> >::_M_fill_initialize(std::vector<cv::Point_<int> >::size_type, int&)’ "
Please kindly suggest. Thank you.
Eric
Re: Nested vector initialization problem
I doubt it would make a difference here, but you should remove that unnecessary cast to int, i.e.,
Code:
vector<vector<Point> > vectorB(4, vector<Point> (vectorA.size(), 0));
If that does not work, post the smallest and simplest program that you expect to compile but which results in the error. After all, your examples does not define Point or vectorA.
Re: Nested vector initialization problem
Quote:
Originally Posted by
laserlight
I doubt it would make a difference here, but you should remove that unnecessary cast to int, i.e.,
Code:
vector<vector<Point> > vectorB(4, vector<Point> (vectorA.size(), 0));
If that does not work, post the smallest and simplest program that you expect to compile but which results in the error. After all, your examples does not define Point or vectorA.
Thank you. I have tried without the casting. But still got the error. As you suggested, a smalll program is listed below. The environment is Ubuntu 12.04. Wondering if this is a c++ library issue...
Code:
#include <stdio.h>
#include <vector>
struct Point {
double x,y;
};
int main(int argc, char* argv[])
{
std::vector<std::vector<Point> > nestVector (4, std::vector<Point>(4,0));
printf("Nested vector test\n");
return 0;
}
Re: Nested vector initialization problem
See the "0" in red below.
Code:
std::vector<std::vector<Point> > nestVector (4, std::vector<Point>(4,0));
The argument should be of type Point, not int ..
Code:
std::vector<std::vector<Point> > nestVector (4, std::vector<Point>(4,Point()));
Re: Nested vector initialization problem
Quote:
Originally Posted by
Ericxx
The environment is Ubuntu 12.04.
That is an OS, not a compiler. You need to tell us the compiler and compiler version you're using.
Second, that line yields a compiler error, while your original post states a linker error.
Quote:
And came across the following error during link stage:
"/usr/include/c++/4.6/bits/stl_vector.h:1080:4: error: no matching function for call to ‘std::vector<cv::Point_<int> >::_M_fill_initialize(std::vector<cv::Point_<int> >::size_type, int&)’ "
That is not a linker error, that is a compiler error.
Regards,
Paul McKenzie
Re: Nested vector initialization problem
Thanks Philip. The problem has already been solved.
Re: Nested vector initialization problem
Quote:
Originally Posted by
Paul McKenzie
That is an OS, not a compiler. You need to tell us the compiler and compiler version you're using.
Second, that line yields a compiler error, while your original post states a linker error.
That is not a linker error, that is a compiler error.
Regards,
Paul McKenzie
Thanks Paul for correcting me. I will put the exact compilation environment for clarification in the next post.