如何保留班级所有公共成员的价值副本。通过访问每个成员来创建显式复制函数不是一个选项,因为程序可以使用同一类的许多可能定义之一进行编译。
示例:两个这样的类是
file: Try1.cpp
class top
{public: int a;
int b;}
file: try2.cpp
class top
{public: int c;
int d;}
file: main.cpp
main()
{
//save all public members of top
// do operations on 'top' which may change its member variables
// check if member variables value changed, may need to restore them
}
在构建项目时,只包含一个try1.cpp或try2.cpp文件