0

How to keep a copy of value of all public members of a class. Create an explicit copy function by accessing each member is not an option because the program can be compiled with one of many possible definitions of the same class.

example: Two such classes are

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
    }

while building the project only one of the try1.cpp or try2.cpp file would be included

Sharad
  • 393
  • 2
  • 16
  • 1
    [tag:c++] [does not have reflection](http://stackoverflow.com/q/41453/78845). Perhaps store your data in a `std::map`? – Johnsyweb Oct 13 '13 at 03:13
  • 1
    `void main()` is not allowed in C++ standard. – xorguy Oct 13 '13 at 03:28
  • This program is ill-formed. It violates the [one-definition rule](http://en.wikipedia.org/wiki/One_Definition_Rule) – Igor Tandetnik Oct 13 '13 at 04:03
  • Why don't you give your class a suitable copy-constructor, assignment operator and equality comparison operator? Then you could write things like `top saved = current; Modify(&current); if (current != saved) {...}` – Igor Tandetnik Oct 13 '13 at 04:06
  • saving the contents of the memory occupied by that class and restoring it later might do the trick. – Ashalynd Oct 13 '13 at 12:36

0 Answers0