Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C+中的嵌套隐式转换+;_C++_Implicit Conversion_Conversion Operator - Fatal编程技术网

C++ C+中的嵌套隐式转换+;

C++ C+中的嵌套隐式转换+;,c++,implicit-conversion,conversion-operator,C++,Implicit Conversion,Conversion Operator,我想在两个层次上进行隐式转换。下面的代码片段是我面临的问题的原型 //Sources class A { public: void print() { std::cout <<"Class A"<< std::endl; } operator int() { return 1; } }; class B { public: void print() { st

我想在两个层次上进行隐式转换。下面的代码片段是我面临的问题的原型

//Sources
class A
{
public:
    void print()
    {
        std::cout <<"Class A"<< std::endl;
    }

    operator int()
    {
        return 1;
    }
};

class B
{
public:
    void print()
    {
        std::cout <<"Class B"<< std::endl;
    }

    operator A()
    {
        return A();
    }
};

class C
{
public:
    void print()
    {
        std::cout <<"Class C"<< std::endl;
    }
    operator B()
    {
        return B();
    }
};


void print_(A a)
{
    a.print();
}

//driver

int main( int argc, char* argv[] )
{
    C c;

    //print_( c ); // compilation error
    //print_( C() ); // compilation error   
    print_( c.operator framework::configuration::B() ); //when explicitly invoked it worked 
    return 0;
}
//来源
甲级
{
公众:
作废打印()
{

标准只允许一个涉及用户定义类型的隐式转换。您有两个,因此编译错误

见12.3/4

最多一个用户定义的转换(构造函数或转换函数)隐式应用于单个 价值观