Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Fixed Help for as Fixed


2
0
Sign in
to vote
Type: Bug
ID: 736213
Opened: 4/10/2012 6:13:17 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

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

[code]

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

[/code]

Error:

-----[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)'
        with
        [
            T=int
        ]
        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)'
        with
        [
            T=int
        ]
        while trying to match the argument list '(ATL::CComSafeArray<T>, ULONG)'

        with
        [
            T=int
        ]

-----[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?).
Details
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(http://support.microsoft.com)
Sign in to post a workaround.