Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 28-01-2009
Member
 
Join Date: Dec 2008
Posts: 70
overloading of operators in C++

Hello everyone, I wanted to know if there's anyone who can help me with this problem:

I'm writing a program in C + + in which I have defined some classes and I did the overloaded operators <<and>> for items related to these classes, but when I compile error: here you put a piece of code:

Code:
class data (public int G,public int M,public int A,
public date ();
void print (oStream & dest) 
{dest <<G <<"/"<< M <<"/"<< A; 
return; 
}

void read (IStream & sorg) 
(int day, month, year; 
char sep ='/'; 
sorg>> day>> sep>> months>> sep>> year; 
G = day; 
M = month; 
A = year; 
return; 
)
)

class Person: public data 
(public: 
string name; 
SURNAME string; 
birth date; 
ADDRESS string; 
MAIL string; 
person (); 
void print (oStream & dest) 
(dest <<NAME <<endl <<NAME <<endl; 
dest <<BIRTH; 
dest <<endl <<ADDRESS <<endl <<MAIL <<endl <<endl; 
return; 
)

void read (IStream & sorg) 
(string name, surname, address, email; 
birth date; 
sorg>> name>> surname; 
sorg>> birth; 
sorg>> address>> email; 
NAME = name; 
SURNAME = surname; 
BIRTH = birth; 
ADDRESS = address; 
MAIL = email; 
return; 
) 
)

/ / other classes and various robe ... 
/ / then out of the definition of any class and before opening the main, I wrote:
oStream & operator <<(oStream & dest, const data & x) 
(x.stampa (dest); 
return dest; 
) 
IStream & operator>> (IStream & sorg, data & x) 
(x.leggi (sorg); 
sorg return; 
) 
oStream & operator <<(oStream & dest, const person & x) 
(x.stampa (dest); 
return dest; 
) 
IStream & operator>> (IStream & sorg, person & x) 
(x.leggi (sorg); 
sorg return; 
)
compile time to give me this error:

no match for 'operator <<' in 'dest <<((person) * this) -> person:: BIRTH'


Why? How do I solve this problem?
Thanks in advance to those who answered!
Reply With Quote
  #2  
Old 28-01-2009
Member
 
Join Date: Mar 2008
Posts: 192
Re: overloading of operators in C++

The next time refers to the code, otherwise you do not understand anything.

Code:
 class data 
  ( 
 public: 
      int G; 
      int M; 
      int A; 
      date (); 
      void print (oStream & dest) 
      ( 
          dest <<G <<"/"<< M <<"/"<< A; 
         return; 
      ) 
      void read (IStream & sorg) 
      ( 
          int day, month, year; 
          char sep ='/'; 
          sorg>> day>> sep>> months>> sep>> year; 
          G = day; 
          M = month; 
          A = year; 
         return; 
      ) 
  ) 
  class Person: public data 
  ( 
 public: 
      string name; 
      SURNAME string; 
      birth date; 
      ADDRESS string; 
      MAIL string; 
      person (); 
      void print (oStream & dest) 
      ( 
          dest <<NAME <<endl <<NAME <<endl; 
          dest <<BIRTH; 
          dest <<endl <<ADDRESS <<endl <<MAIL <<endl <<endl; 
         return; 
      ) 
      void read (IStream & sorg) 
      ( 
          string name, surname, address, email; 
          birth date; 
          sorg>> name>> surname; 
          sorg>> birth; 
          sorg>> address>> email; 
          NAME = name; 
          SURNAME = surname; 
          BIRTH = birth; 
          ADDRESS = address; 
          MAIL = email; 
         return; 
      ) 
  ) 

  / / other classes and various robe ... 
  / / then out of the definition of any class and before opening the main, I wrote: 

  oStream & operator <<(oStream & dest, const data & x) 
  ( 
      x.stampa (dest); 
      return dest; 
  ) 
  IStream & operator>> (IStream & sorg, data & x) 
  ( 
      x.leggi (sorg); 
      sorg return; 
  ) 
  oStream & operator <<(oStream & dest, const person & x) 
  ( 
      x.stampa (dest); 
      return dest; 
  ) 
  IStream & operator>> (IStream & sorg, person & x) 
  ( 
      x.leggi (sorg); 
      sorg return; 
  )
Missing piece of code where the error, it is impossible to understand.
Reply With Quote
  #3  
Old 28-01-2009
Member
 
Join Date: Dec 2008
Posts: 70
Re: overloading of operators in C++

ok, you're right ...

the error is on this line of class "person" in the function "print":

Code:
 dest <<BIRTH;
Reply With Quote
  #4  
Old 28-01-2009
Member
 
Join Date: Mar 2008
Posts: 192
Re: overloading of operators in C++

Move those operators <<before the definition of classes.
It is also good use never use variables State capitals. For the reading of the code will also put a space between operators and arguments.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "overloading of operators in C++"
Thread Thread Starter Forum Replies Last Post
What is constructor overloading in c++ Mast Maula Software Development 4 08-01-2011 10:34 AM
Method overloading c#.net raju_srk Software Development 1 22-11-2010 07:00 PM
Function overloading with polymorphism Mega Member Software Development 3 02-10-2009 03:35 PM
Error in Operator Overloading DutchDude Software Development 2 13-05-2009 11:54 PM
Error in function overloading CitricAcid Software Development 3 06-05-2009 10:50 AM


All times are GMT +5.5. The time now is 10:00 AM.