Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Overloaded << O...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 44632 of 48417
Post > Topic >>

Overloaded << Operator Error ?? why

by pallavsingh81@[EMAIL PROTECTED] Apr 10, 2008 at 10:35 AM

#include<iostream.h>

//prefix and postfix Operator overloading // Inorder to see effect
overload operator <<

class A
{
  public :
  int i,j;
  A(int _i,int _j):i(_i),j(_j){}
  A & operator++();
  const A operator++(int);

};


A& A::operator++()
{
  this->i = this->i + 1;
  this->j = this->j +1 ;
  return *this;
}



const A A::operator++(int)
{
 A obj = *this;
 this->i = this->i + 1;
 this->j = this->j +1 ;

 return obj;
}

ostream & operator << (ostream & out ,  A & obj)
{
   out<<"Value of i  "<<obj.i<<endl;
   out<<"Value of j  "<<obj.j<<endl;
   return out;
}

int main()
{

A obj(10,20);
cout<<++obj;
cout<<obj++;  // Error Why ????????????????

return 0;
}
 




 2 Posts in Topic:
Overloaded << Operator Error ?? why
pallavsingh81@[EMAIL PROT  2008-04-10 10:35:09 
Re: Overloaded << Operator Error ?? why
Rolf Magnus <ramagnus@  2008-04-10 19:39:51 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 2:57:19 CST 2008.