企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
尽管函数转换成成员函数的过程是机械式的,但还是有一些古怪的地方。例如,after函数对两个Time对象进行操作,而不仅仅是一个,我们不能使它俩都成为隐式的。而需要在其中一个对象上调用这个函数,并把另一个对象作为参数传递给它。 在函数中,我们隐式地引用其中一个对象,而继续使用点符号来访问另一对象的实例变量。 ~~~ bool Time::after (const Time& time2) const{ if(hour > time2.hour) return true; if(hour < time2.hour) return false; f(minute > time2.minute) return true; if(minute < time2.minute) return false; if(second > time2.second) return true; return false; } ~~~ 调用此函数: ~~~ if (doneTime.after (currentTime)) { cout << "The bread will be done after it starts." <<endl; } ~~~ 调用过程可以这么理解: “如果done-time在current-time之后,那么...”