Exercises 1、写出广义表表示法表示的树的类声明,并给出如下成员函数的实现 (1) operator>()接收用广义表表示法表示的树作为输入,建立广义表的存储表示 (2)复制构造函数用另一棵表示为广义表的树初始化 (3) operator==()测试用广义表表示的两棵树是否相 (4) operator* is overloaded //Pointer ToMemberOperator cpp using namespace class Dog i put int run(int i)const i cout * must return an object ∥ that has an operator class Function object i Dog ptr PMF pmem; public l Save the object pointer and member pointer otr( wp), pmem(pmf)i cout *pmem)(i) // Make the call
Exercises6 1、写出广义表表示法表示的树的类声明,并给出如下成员函数的实现: (1) operator>>( ) 接收用广义表表示法表示的树作为输入,建立广义表的存储表示; (2) 复制构造函数 用另一棵表示为广义表的树初始化一棵树; (3) operator= = ( ) 测试用广义表表示的两棵树是否相等; (4) operator* is overloaded. //PointerToMemberOperator.cpp #include using namespace std; class Dog { public: int run(int i) const { cout * must return an object // that has an operator(): class FunctionObject { Dog* ptr; PMF pmem; public: // Save the object pointer and member pointer FunctionObject(Dog* wp, PMF pmf) : ptr(wp), pmem(pmf) { cout *pmem)(i); // Make the call }
}; return FunctionObject( this, pmf) Int Dog: PMF pmf =&Dog: run cout*pmf)(2)*pmf)(3)<<endl }∥:
}; FunctionObject operator->*(PMF pmf) { cout *" *pmf)(1) *pmf)(2) *pmf)(3) << endl; } ///:~