In the OpenCV library there is a
typedef const _InputArray& InputArray;
In our code we have the following function definition:
void wimshow(const String& winName, InputArray &img) {
When compiling this the following error occurs:
error: cannot declare reference to 'cv::InputArray {aka const class cv::_InputArray&}'
void wimshow(const String& winName, InputArray &img) {
The weird thing is that this error only occurs using GCC 4.8.1 in the Cray environment. Compiling in a normal Linux environment with GCC 4.8.1 works without errors.
At first glance I would say that a reference to a reference type is not very meaningful anyway but I am curious about what could cause the different compiler behavior!?
This appears to be a C++03/C++11 difference.
In C++11, the extra
&
(and theconst
, incidentally) are supposed to be ignored:The pertinent example here is
r1
; althoughtypedef int& LRI
isn't precisely like yourtypedef
, the example is equivalent due to the following passage having already dropped yourconst
:However, the
[C++11: 8.3.2/6]
wording does not exist in C++03! In fact, we can compare behaviours between the two languages with the following example program:error: cannot declare reference to 'T2 {aka struct T1&}'
(ignoring warnings about unused variables)
So, check your compilation flags on each platform to ensure that you're using the same language on both. It may be that the default on the Cray is C++03, but the default on your platform is C++11. Use the
-std=c++03
/-std=c++11
flag to state which to use explicitly.