operator TYPE()
От: Aera Беларусь  
Дата: 10.10.04 18:25
Оценка:
Не могу понять, почему в указанном коде не работает последняя строка. Ведь при преобразовании должен использоваться operator data::pcursor_maker_t()?

  typedef boost::shared_ptr<class data::cursor_maker> pcursor_maker_t;
    
    data::pcursor_maker_ref ref=collection_.access();
  data::pcursor_maker_t maker1 = ref.operator data::pcursor_maker_t(); // ок
  data::pcursor_maker_t maker2 = (data::pcursor_maker_t)ref; 
    //error C2440: 'type cast' : cannot convert from 'class data::pcursor_maker_ref' to 
    //'class boost::shared_ptr<class data::cursor_maker>' 
    // No constructor could take the source type, or constructor overload resolution was ambiguous


ЗЫЖ VC6.0
... << RSDN@Home 1.1.4 beta 3 rev. 185>>
--
RedApe
Re: operator TYPE()
От: MaximE Великобритания  
Дата: 10.10.04 19:39
Оценка:
Aera wrote:

> Не могу понять, почему в указанном коде не работает последняя строка. Ведь при преобразовании должен использоваться operator data::pcursor_maker_t()?

>
>
>   typedef boost::shared_ptr<class data::cursor_maker> pcursor_maker_t;
>     
>     data::pcursor_maker_ref ref=collection_.access();
>   data::pcursor_maker_t maker1 = ref.operator data::pcursor_maker_t(); // ок
>   data::pcursor_maker_t maker2 = (data::pcursor_maker_t)ref;
>     //error C2440: 'type cast' : cannot convert from 'class data::pcursor_maker_ref' to
>     //'class boost::shared_ptr<class data::cursor_maker>'
>     // No constructor could take the source type, or constructor overload resolution was ambiguous
>


Похоже, что у тебя здесь ambiguity — для преобразования из pcursor_maker_ref в pcursor_maker_t компилятор находит две conversion sequence и обе из них с user-defined conversion (шаблонный к-тор у shared_ptr и твой operator pcursor_maker_t()), что делает обе conversion sequence равнозначными.

--
Maxim Yegorushkin
Posted via RSDN NNTP Server 1.9 gamma
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.