Who faced this problem when working with OpenCV? C ++ language, I work in VS2013.

Error 1 error C2864: "cv :: sfinae :: has_parenthesis_operator :: value": a static data item with an initializer inside a class must have an immutable integer type const c: \ users \ admin \ documents \ visual studio 2013 \ projects \ opencv2 \ core \ cvstd_wrapper.hpp 52 1 Second_test

That's actually all the code:

#include "opencv2/core/core.hpp" #include <opencv2/core/types_c.h> #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <opencv2/core/core_c.h> #include <opencv2/imgproc/imgproc_c.h> #include <opencv2/highgui/highgui_c.h> #include <iostream> int main(int argc, char** argv) { system("pause"); return 0; } 
  • Maybe the studio is just too old? - HolyBlackCat
  • Did you compile libraries from OpenCV sources, or did you take already compiled libraries? Next, do you pass the canonical test with the only #include "opencv2 / opencv.hpp"? - Alexander Muksimov
  • @ Alexander Muksimov: If cvstd_wrapper.hpp is an interface header file, then it does not matter whether the library is already compiled or not. - AnT pm
  • @AnT I asked two different questions. Unfortunately, there are jambs in OpenCV, when everything works in debug, but does not work in release, and when the header is mixed from different versions, and when OpenCV has to be collected again. Your deep analysis in the answer very clearly confirms that the new version of OpenCV is a new hemorrhoids :). From me "+" - Alexander Muksimov

1 answer 1

The declaration of this line in cvstd_wrapper.hpp is

 static CV_CONSTEXPR bool value = type::value; 

Such an declaration will be correct in C ++ only if CV_CONSTEXPR is replaced with constexpr or const (or inline , but constancy is implied here).

The macro definition in cvdef.h is

 #ifndef CV_CONSTEXPR # if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) # define CV_CONSTEXPR constexpr # endif #endif #ifndef CV_CONSTEXPR # define CV_CONSTEXPR #endif 

That is, for some reason, they do not define CV_CONSTEXPR as const when they cannot define it as constexpr . This is strange.

History of changes is 22 days ago.

  #ifndef CV_CONSTEXPR - # define CV_CONSTEXPR const + # define CV_CONSTEXPR #endif 

That is, const was still there, but someone "alalek" mowed this const nafig. Most likely he corrected something else, but as a result, he “killed” this place in cvstd_wrapper.hpp . Moreover, judging by the fact that this is a fallback, this “tug of war” has been going on for some time. Typical open source mess.

As can be seen from the comment to this commit, in other places of the code they use declarations like

 static CV_CONSTEXPR const int var = ...; 

with obvious const . But since "alalek" made this correction, then you need to bring to this view - with an obvious const - all such places, including cvstd_wrapper.hpp too.

Either wait until you fix this joint, or take a newer version of VS and work in C ++ 11 mode or higher.