just as the title says i have a problem with serializzing class which has a pointer to class. so this is a mock-up of my class structure

class X{

 private:
    int number;
 public:
    int set_number(int);
    int get_number(void);
//I'm defining the stream operators so class will act as primitive data type
    friend istream& operator>>(istream& in,X& x)
      {
         in>>x.number;
         return in;
      }
    friend ostream& operator<<(ostream& out,const X& x)
      {
        out<<x.number<<endl;
        return out;
      }
};//classX

class A{
     vector<X*> Ccontainer;

public:
     friend ostream& operator<<(ostream& out,const A& a)
       {
         out<<(int)Ccontainer.size()<<endl;
         for(int i=0;i<=Ccontainer.size();i++)
              out<<Ccontainer.at(i)<<endl;
         return out;
       }
     friend istream& operator>>(istream& in,A& a)
       {
         int n;
         in>>n;
         a.CContainer.reserve(n);
         for(int i=0;i<=n;i++)
            in>>a.Ccontainer[i];
         return in;
        }
};//class A

i'm having problems with the second class;the problem is with the insertion operator,what am I missing here?

vector<X*> Ccontainer; is a vector of pointers. You call the >> operator with a pointer as an argument ( a.Ccontainer[i] ) but define it as taking a reference ( operator>>(istream& in,X& x) ).

Thats the best I can tell without you describing the actual error you are experiencing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.