Why is this ambiguity here?

前端 未结 6 1171
南笙
南笙 2020-12-02 20:35

Consider I have the following minimal code:

#include 

template
struct TData
{
    typedef typename boost:         


        
6条回答
  •  误落风尘
    2020-12-02 21:00

    I don't know what's the exact answer, but...

    Because of this operator:

    operator ptr_t & () { return data; }
    

    there exist already built-in [] operator (array subscription) which accepts size_t as index. So we have two [] operators, the built-in and defined by you. Booth accepts size_t so this is considered as illegal overload probably.

    //EDIT
    this should work as you intended

    template
    struct TData
    {
        ptr_t data;
        operator ptr_t & () { return data; }
    };
    

提交回复
热议问题