title: c++ passing unknown type to a function and any Class type definition
body: <p>I am trying to create a generic class to write and read Objects to/from file.
  Called it ActiveRecord class</p>
  
  <p>only has one method, which saves the class itself:</p>
  
  <pre><code>void ActiveRecord::saveRecord(){
   string fileName = "data.dat";
  
   ofstream stream(fileName.c_str(), ios::out);
   if (!stream) {
    cerr &lt;&lt; "Error opening file: " &lt;&lt; fileName &lt;&lt; endl;
    exit(1);
   }
   stream.write(reinterpret_cast&lt;const char *&gt; (this), sizeof(ActiveRecord));
   stream.close();
  }
  </code></pre>
  
  <p>now I'm extending this class with User class:</p>
  
  <pre><code>class User : public ActiveRecord
  {
   public:
    User(void);
    ~User(void);
    string name;
    string lastName;
  };
  </code></pre>
  
  <p>to create and save the user I would like to do something like:</p>
  
  <pre><code>User user = User();
  user.name = "John";
  user.lastName = "Smith"
  user.save();
  </code></pre>
  
  <p>how can I get this ActiveRecord::saveRecord()  method to take any object, and class definition so it writes whatever i send it:</p>
  
  <p>to look like:</p>
  
  <pre><code>void ActiveRecord::saveRecord(foo_instance, FooClass){
   string fileName = "data.dat";
  
   ofstream stream(fileName.c_str(), ios::out);
   if (!stream) {
    cerr &lt;&lt; "Error opening file: " &lt;&lt; fileName &lt;&lt; endl;
    exit(1);
   }
   stream.write(reinterpret_cast&lt;const char *&gt; (foo_instance), sizeof(FooClass));
   stream.close();
  }
  </code></pre>
  
  <p>and while we're at it, what is the default Object type in c++.
  eg.
  in objective-c it's id
  in java it's Object
  in AS3 it's Object
  what is it in C++??</p>