2

in my application i have a function which receives a cv::Mat object by reference. here is function's declaration:

     void getChains(cv::Mat &img,std::vector<chain> &chains,cv::Mat &ch,char p=0,int sx=0,int sy=0);

this function is recursive, and aaa is not really needed at the first call from the main function, so i just declared an empty aaa to pass it to the function call. in subsequent recursive calls function generates its own ch Mat objects.

std::vector<chain> chains1;
cv::Mat aaa();

getChains(bin1,chains1,aaa);

however, the compiler returns an error:

main.cpp:75: error: invalid initialization of non-const reference of type ‘cv::Mat&’ from a temporary of type ‘cv::Mat (*)()’ aux.h:21: error: in passing argument 3 of ‘void getChains(cv::Mat&, std::vector >&, cv::Mat&, char, int, int)’

if i change aaa declaration to

        cv::Mat aaa=cv::Mat();

it compiles without a problem.

the function is passed a binary image img and gets all the pixel groups in which pixels stick together (chains) and stores all the pixels' coordinates in the chains vector. Is there perhaps already an existing function within openCV that does a similar thing?

thanks

Jaka
  • 1,353
  • 2
  • 10
  • 16

1 Answers1

5

This is a function definition: cv::Mat aaa();. What you actually want to write is cv::Mat aaa;

coproc
  • 6,027
  • 2
  • 20
  • 31
  • of course! :) thanks. don't know why i thought it evokes the default constructor of cv::Mat – Jaka Oct 16 '12 at 16:46
  • 1
    This is an example of [the most vexing parse](https://en.wikipedia.org/wiki/Most_vexing_parse). See also [Most vexing parse: why doesn't A a(()); work?](http://stackoverflow.com/q/1424510/256138) – rubenvb Mar 09 '15 at 14:01
  • In C++11 and up, you also have the option to use `cv::Mat aaa{};` to not fall into the most-vexing parse trap. – Ela782 Oct 01 '15 at 20:56