mardi 26 janvier 2021

if code is using "implicit boolean conversions".can valid c++03 code, break in c++11?

With addition of change in c++11

change:Change: Specify use of explicit in existing boolean conversion operators (https://timsong-cpp.github.io/cppwp/n4618/diff.cpp03.input.output)

can valid c++03 code break in c++11?

struct abt {

        public:

        abt(int a, double b){}

         abt(int a){cout<<"int"<<endl;}

        abt(bool b) {cout<<"bool"<<endl;}

       abt(bool b,bool c) {cout<<"bool bool"<<endl;}

       operator bool() const { return true; } };

     int main() {

    abt is("a",3);
    if (is)
        std::cout << "success";
    if( is == true)
        std::cout << "success";

    return 0;
}

this valid c++03 code giving same output in c++11,output with implicit boolean conversion is also same in in c++11. Is there smthing wrong with rule ?

Aucun commentaire:

Enregistrer un commentaire