C2666 error - does this violate the C++ standard ?  
Author Message
Rakosnicek





PostPosted: Visual C++ Language, C2666 error - does this violate the C++ standard ? Top

Consider the following example below that generates the C2666 error. I believe this violates the C++ standard section 13.3.3.2 paragraph 3. Do you agree

template <class Type>

class MyArray

{

MyArray();

Type& operator[](int);

operator const Type*() const

{ return mpData; }

Type* mpData;

};

template <class Type>

Type& MyArray<Type>::operator[](int ind)

{ return mpData[ind]; }

void SetElement(MyArray<double>& a)

{

unsigned int i=0;

a[ i ] = 0.0;

}



Visual C++15  
 
 
einaros





PostPosted: Visual C++ Language, C2666 error - does this violate the C++ standard ? Top

I agree. Report it at http://connect.microsoft.com/VisualStudio, if it's not registered there already.

 
 
Marius Bancila





PostPosted: Visual C++ Language, C2666 error - does this violate the C++ standard ? Top

Consider the following example below that generates the C2666 error. I believe this violates the C++ standard section 13.3.3.2 paragraph 3. Do you agree

And what exactly does the paragraph say



 
 
einaros





PostPosted: Visual C++ Language, C2666 error - does this violate the C++ standard ? Top

 

And what exactly does the paragraph say

13.3.3.2 is "Ranking implicit conversion sequences".

To use MyArray::operator[](int), the standard conversion subclause 4.7 (Integral Conversion) is used for the unsigned -> signed conv.

MyArray::operator const Type*, however, is a user defined conversion, and 13.3.3.2 - 2 defines that this should be ranked lower than the standard conversion.

Even the compile error puzzles me in this case. "'MyArray<Type>::operator []' : 2 overloads have similar conversions" makes it sound like there are actually two or more subscript operators with similar conversions.



 
 
Brian Kramer





PostPosted: Visual C++ Language, C2666 error - does this violate the C++ standard ? Top

I took the error to mean that the compiler can either use the user-defined subscript operator, or the built-in one after MyArray<double> has been converted to double*.

I found it interesting that this issue hasn't been seen earlier.

Brian


 
 
einaros





PostPosted: Visual C++ Language, C2666 error - does this violate the C++ standard ? Top

I took the error to mean that the compiler can either use the user-defined subscript operator, or the built-in one after MyArray<double> has been converted to double*.

It has to, but I still find the wording less informative than it perhaps should be. That may just be me, though