title: Data Conversion from one class type to another class type
body: <p>I was trying to convert one class type data to another class type therefore I was using casting operator method in my oops program in c++.</p>
  
  <pre><code>class example2;
  class example1
  {
     int id;
     int numbers;
     int cost;
  public:
     example1(int a, int b, int c)
     {
       id=a;
       numbers=b;
       cost=c;
     }
  
  // getid() added here
  // getnumber() added here
  // getcost() added here
  
     operator example2()
     {
      example2 temp;
      temp.id=id;
      temp.value=numbers*cost;
      return temp;
     }
  };
  class example2
  {
     int id;
     int value;
  public:
     example2(int x,int y){
       id=x;
       value=y;
     }
    void display(){
      cout&lt;&lt;"id "&lt;&lt;id&lt;&lt;endl;
      cout&lt;&lt;"value "&lt;&lt;value&lt;&lt;endl;
    }
  };
  </code></pre>
  
  <p>when I was using casting from example1 to example2. It is showing error.</p>
  
  <pre><code>int main()
  {
    example1 s1(100,5,140.0);
    example2 s2;
    s2=s1;
    s2.display();
    return 0;
  }
  </code></pre>
  
  <p>it is giving error but why?. I made an operator overloading member function in example1 class because object of example1 has to be changed into object of example2.So this function invoked from class example1's method only which I think.It should be correct</p>
  
  <p>Error was like:</p>
  
  <p><strong>error: return type 'class example2' is incomplete and 
  example2 temp; has incomplete type</strong></p>
  
  <p>Somehow I resolved this in another way I added a constructor in example2 class side:</p>
  
  <pre><code>example2(example1 e)
  {
    id=e.getid(); //these functions already added in my code i didnt mentioned them in here.
    value=e.getnumber()*e.getcost();
  }
  </code></pre>
  
  <p>and make comment of 'operator example2()' part in example1.
  now it is working.
  But previous way was not accepting. Please help me to correct me in my previous way of doing this thing.</p>