0

如何保留类的所有公共成员的值的副本。通过访问每个成员来创建显式复制函数不是一种选择,因为可以使用同一类的许多可能定义之一来编译程序。

示例:两个这样的类是

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 文件之一

4

0 回答 0