ATL::CComSafeArray::operator[] ambiguity - by Giovanni Dicanio

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 736213 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 4/10/2012 6:13:17 AM
Access Restriction Public


ATL::CComSafeArray::operator[] is overloaded with both LONG and int indexes.
This makes code like this fail to compile:


CComSafeArray<int> sa;
for (ULONG i = 0; i < sa.GetCount(); i++)
    cout << sa[i] << endl;



-----[error begin]-----

error C2593: 'operator [' is ambiguous
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\INCLUDE\atlsafe.h(265): could be 'ATL::_ATL_AutomationType<INT>::_typewrapper &ATL::CComSafeArray<T>::operator [](LONG)'
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\INCLUDE\atlsafe.h(257): or       'ATL::_ATL_AutomationType<INT>::_typewrapper &ATL::CComSafeArray<T>::operator [](int)'
        while trying to match the argument list '(ATL::CComSafeArray<T>, ULONG)'


-----[error end]-----

The code compiles fine if CComSafeArray::GetAt() is used instead of the operator[] overload, but this "workaround" seems kind of ugly (if there is an operator[] overload, which seems natural for accessing array elements given the index, why should a verbose GetAt() method be used?).
Sign in to post a comment.
Posted by Microsoft on 10/10/2012 at 10:58 AM
Hello Giovanni,

Thank you very much for your feedback. The problem has been fixed in next release of Visual Studio.

Windows C++ Libraries Team
Lukasz Chodorski
Posted by MS-Moderator08 [Feedback Moderator] on 4/10/2012 at 7:43 PM
Thank you for submitting feedback on Visual Studio 11 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 4/10/2012 at 6:49 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(