Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2003-09-05 10:42:56


> Vladimir Prus wrote

>>class C {
>>public:
>> explicit C(int) {}
>>};
>
>>int main()
>>{
>> int i = 0;
>> static_cast<C>(i);
>> return 0;
>>}
>

>If I remove "explicit" I have another error from g++:

>/home/ghost/Work/boost/boost/archive/basic_binary_oarchive.hpp: In member
> function `boost::archive::basic_binary_oarchive<OStream>&
> boost::archive::basic_binary_oarchive<OStream>::operator<<(const T&)
>[with T
> = unsigned int, OStream = std::ostream]':
>./src/binary_oarchive.cpp:25: instantiated from here
>/home/ghost/Work/boost/boost/archive/basic_binary_oarchive.hpp:130: error:
>ISO
> C++ says that `void
> boost::archive::basic_binary_oarchive<OStream>::save_override(const T&,
>long
> int) [with T = unsigned int, OStream = std::ostream]' and `void
> boost::archive::basic_binary_oarchive<OStream>::save_override(const
> boost::archive::object_reference_type&, int) [with OStream =
>std::ostream]'
> are ambiguous even though the worst conversion for the former is better
>than
> the worst conversion for the latter

>That's most likely because removing "explicit" adds the second function to
>the list of viable one for overload resolution.

>Hmm... I don't know how to make 3.3 happy. Not to mention that I don't
>understand what's "worst conversion", in the error message.

>- Volodya

I went through this before which resulted in adding "explicit".

Is there any reason we can't just change the instances where the problem
occurs from

class C {
public:
    explicit C(int) {}
};

int main()
{
    int i = 0;
    static_cast<C>(i);
    return 0;
}

to:

class C {
public:
    explicit C(int) {}
};

int main()
{
    int i = 0;
    C(i);
    return 0;
}

and be done with it. After all that's all the static_cast<C>(i) does. I believe
this only occurs in a few places ( < 25 ?) but I can't know for sure as
I don't have 3.3.

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk