C++ - Error: expected type-specifier while creating C wrapper for OpenCV's cv::Scalar::all

StackOverflow https://stackoverflow.com/questions/22277147

  •  11-06-2023
  •  | 
  •  

문제

Here is the code I'm compiling...I'm creating a C wrapper for cv::Scalar::all so I can wrap in another language...

cpp

 Scalar* cv_create_ScalarAll(double val)
{
    return new Scalar::all(val);
}

hpp

Scalar* cv_create_ScalarAll(double val);

compile with 'g++ -Wall -shared -fPIC -o opencv-glue.so opencv-glue.cpp' on Ubuntu Trusty Tahr

Im getting this error

error: expected type-specifier
     return new Scalar::all(val);

I just wrote a similar function successfully to wrap cv::Scalar in C and so did the same for this but its not working....I've tried removing the New adding a cv:: and Googled to no avail....any help is appreciated=) ^

도움이 되었습니까?

해결책

You are getting this error because Scalar::all is not a type (unlike Scalar). Just removing the new would not work because Scalar::all returns an instance of Scalar with local storage. Most likely want you want is:

Scalar* cv_create_ScalarAll(double val)
{
    return new Scalar(Scalar::all(val));
}

다른 팁

The new operator creates an object and allocates its memory, therefore it needs type of the new object. In your code, a call to method is provided instead of the type. You can check the method in the OpenCV documentation, but it looks like it is returning a scalar - so if you write just a wrapper for this method, the call to function is completely enough.

Scalar* cv_create_ScalarAll(double val)
{
    return Scalar::all(val);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top