gpt4 book ai didi

c++ - 重载运算符

转载 作者:行者123 更新时间:2023-11-28 05:51:53 25 4
gpt4 key购买 nike

<分区>

谁能解释一下这个重载运算符是如何调用的?我了解动态转换和条件三元的作用,但我不了解运算符。

头文件:

 // ------------------------------------------------------
Class Base
{
public:
Base ();
operator Derived &();
private:
Base * me;
}
//--------------------------------------------------
Class Derived : public Base
{
public:
Derived ()
}
//----------------------------------------------------
inline Base::operator Derived &() {return *(dynamic_cast<Derived *>(me?me:this));}

源文件:

Base::Base()
{
me = new Derived()
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com