Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有人知道如何在 C++ 中为一个类实现强制转换规则吗?
假设我有一个具有双重类型成员的 Mark 类。我希望这个类可以加倍:
Mark m(9); double d = (double)m;
是否有可能做到这一点?
你可以operator double()在你的班级里面。例如
operator double()
class Mark { //... public: operator double() { return the_member; } };