C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 1st, 2003, 03:02 PM
kavi_s kavi_s is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 24 kavi_s User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Overloading <<

Hi, i am having trouble overloading the << operator for a class that I have written. Suppose my class is def as follows:

Code:
class Set
{
    public:
        Set(int elem_num, int option)
        {
           for(int i=0; i<elem_num; i++)
           {
              if(option==FULL_SET)
                 bits.push_back(1);
             else
                 bits.push_back(0);
           }
        }

        Set operator || (Set set)
        {
           Set result;
           for(int i=0; i<bits.size(); i++)
          {
             result.bits.push_back((bits[i] || set.bits[i]));
          }
           return result;
       }

        friend ostream &operator<<(ostream& out, const Set &set)
        {
           out << "{";
           for(int i=0; i<set.bits.size(); i++)
          {
              if(i==set.bits.size()-1)
                 out << set.bits[i] << "}";
             else
                 out << set.bits[i] << ", ";
         } 
       }

    private:
        bit_vector bits;
};



This is the driver program. the problem is that I can't output the the AND of A and B using line "TWO". I get this error when compiling:
"no match for `Set & << ostream & (&)(ostream &)'
candidates are: class ostream & operator <<(ostream &, const Set &)"

If I compile with line "ONE", everything is fine, and I get the desired output. Does anyone know what I need to change so that it outputs correctly and I don't have to include the parentheses () ???? Thanks!!


Code:
		  
int main(int argc,char **argv)
{
   Set A(5, FULL_SET);
   Set B(5, EMPTY_SET);
   
   cout << "Set A: " << A << endl;
   cout << "Set B: " << B << endl;
   
   cout << "A && B " << (A&&B) << endl;   /* ONE */
   cout << "A && B" << A && B << endl;   /* TWO */
   
   return(0);
  
}

Reply With Quote
  #2  
Old June 1st, 2003, 03:06 PM
kavi_s kavi_s is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 24 kavi_s User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
OOPS i meant to include the && function

Oops, sorry I had written a || and a && function, and included the wrong one by mistake, but it's basically the same as the || except that it ands the values instead of oring them.....SOrry about that

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Overloading <<

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap