C++0x Error: overloading a function with std::shared_ptr to const argument is ambiguous

后端 未结 4 595
醉梦人生
醉梦人生 2021-01-18 09:04

Suppose I have two unrelated classes A and B. I also have a class Bla that uses boost::shared_ptr like t

4条回答
  •  别那么骄傲
    2021-01-18 09:50

    http://bytes.com/topic/c/answers/832994-shared_ptr-derived-classes-ambiguitity-overloaded-functions

    struct yes_type { char dummy; };
    struct no_type { yes_type a; yes_type b; };
    
    template < typename From, typename To >
    class is_convertible
    {
        private:
            static From* dummy ( void );
    
            static yes_type check ( To );
    
            static no_type check ( ... );
    
        public:
    
            static bool const value = sizeof( check( *dummy() ) ) == sizeof( yes_type );
    
    }; // is_convertible
    

    An in boost's shared_ptr.h, change the constructor signature to:

    template
    shared_ptr(shared_ptr const & r,
        typename enable_if::value, void*>::type = 0
        ): px(r.px), pn(r.pn) // never throws
    {
    }
    

提交回复
热议问题