Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. CPPTOTD

CPPTOTD

Scheduled Pinned Locked Moved The Lounge
csharpc++graphicslearning
13 Posts 11 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Rama Krishna Vavilala

    C++ trick of the day. As my work day was coming near to close, I was browsing to the source code of Generative Programming book.. I saw some code like this :-

    Matrix m = 1, 2, 3 ,4 ,5;

    That time I relaized that , operator can also be overloaded. I wrote something like this :-

    class dummy
    {
    public:
    std::vector vec;

    dummy& operator,(const int& val)
    {
    	vec.push\_back(val);
    	return \*this;
    }
    
    dummy& operator = (const int& val)
    {
    	vec.push\_back(val);
    	return \*this;
    }
    

    };

    int main(int argc, char* argv[])
    {
    dummy dum;

    dum = 1, 2, 3, 4, 5;
    
    for(int i = 0; i < dum.vec.size(); i++)
    {
    	cout << dum.vec\[i\];		
    }
    
    return 0;
    

    }

    This is one of the neatest tricks I have seen with C++. Simply amazing. C# is fundamentally broken. - Christian Graus

    C Offline
    C Offline
    Chris Losinger
    wrote on last edited by
    #2

    crazy. just last night, i was wondering if you could override the comma - really.


    As always, it's bread and circuses. And while bread is down right now, circuses are way up.

    L 1 Reply Last reply
    0
    • C Chris Losinger

      crazy. just last night, i was wondering if you could override the comma - really.


      As always, it's bread and circuses. And while bread is down right now, circuses are way up.

      L Offline
      L Offline
      Le centriste
      wrote on last edited by
      #3

      ?: is the only operator you cannot override in C++ Michel It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
      - TreeBeard

      M 1 Reply Last reply
      0
      • R Rama Krishna Vavilala

        C++ trick of the day. As my work day was coming near to close, I was browsing to the source code of Generative Programming book.. I saw some code like this :-

        Matrix m = 1, 2, 3 ,4 ,5;

        That time I relaized that , operator can also be overloaded. I wrote something like this :-

        class dummy
        {
        public:
        std::vector vec;

        dummy& operator,(const int& val)
        {
        	vec.push\_back(val);
        	return \*this;
        }
        
        dummy& operator = (const int& val)
        {
        	vec.push\_back(val);
        	return \*this;
        }
        

        };

        int main(int argc, char* argv[])
        {
        dummy dum;

        dum = 1, 2, 3, 4, 5;
        
        for(int i = 0; i < dum.vec.size(); i++)
        {
        	cout << dum.vec\[i\];		
        }
        
        return 0;
        

        }

        This is one of the neatest tricks I have seen with C++. Simply amazing. C# is fundamentally broken. - Christian Graus

        S Offline
        S Offline
        Shog9 0
        wrote on last edited by
        #4

        Nice :)

        [Shog9]

        1 Reply Last reply
        0
        • R Rama Krishna Vavilala

          C++ trick of the day. As my work day was coming near to close, I was browsing to the source code of Generative Programming book.. I saw some code like this :-

          Matrix m = 1, 2, 3 ,4 ,5;

          That time I relaized that , operator can also be overloaded. I wrote something like this :-

          class dummy
          {
          public:
          std::vector vec;

          dummy& operator,(const int& val)
          {
          	vec.push\_back(val);
          	return \*this;
          }
          
          dummy& operator = (const int& val)
          {
          	vec.push\_back(val);
          	return \*this;
          }
          

          };

          int main(int argc, char* argv[])
          {
          dummy dum;

          dum = 1, 2, 3, 4, 5;
          
          for(int i = 0; i < dum.vec.size(); i++)
          {
          	cout << dum.vec\[i\];		
          }
          
          return 0;
          

          }

          This is one of the neatest tricks I have seen with C++. Simply amazing. C# is fundamentally broken. - Christian Graus

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #5

          Rama Krishna wrote: C# is fundamentally broken. - Christian Graus So true in this case. Us C# monkeys can't even overload the = operator :( Give them a chance! Do it for the kittens, dear God, the kittens!

          1 Reply Last reply
          0
          • R Rama Krishna Vavilala

            C++ trick of the day. As my work day was coming near to close, I was browsing to the source code of Generative Programming book.. I saw some code like this :-

            Matrix m = 1, 2, 3 ,4 ,5;

            That time I relaized that , operator can also be overloaded. I wrote something like this :-

            class dummy
            {
            public:
            std::vector vec;

            dummy& operator,(const int& val)
            {
            	vec.push\_back(val);
            	return \*this;
            }
            
            dummy& operator = (const int& val)
            {
            	vec.push\_back(val);
            	return \*this;
            }
            

            };

            int main(int argc, char* argv[])
            {
            dummy dum;

            dum = 1, 2, 3, 4, 5;
            
            for(int i = 0; i < dum.vec.size(); i++)
            {
            	cout << dum.vec\[i\];		
            }
            
            return 0;
            

            }

            This is one of the neatest tricks I have seen with C++. Simply amazing. C# is fundamentally broken. - Christian Graus

            J Offline
            J Offline
            Jorgen Sigvardsson
            wrote on last edited by
            #6

            Evil stuff indeed.

            int operator,(int x, int y)
            {
            return x + y;
            }

            int main(void)
            {
            printf("This %d is insane!", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
            return 0;
            }

            This kind of stuff could break the whole language! Are you sure you can overloard the comma operator without any restrictions? If you were another man, I would kill you where you stand! The line must be drawn here! This far, no further! They must pay for what they've done!

            C T 2 Replies Last reply
            0
            • L Le centriste

              ?: is the only operator you cannot override in C++ Michel It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
              - TreeBeard

              M Offline
              M Offline
              Michael Dunn
              wrote on last edited by
              #7

              Don't forget . :) --Mike-- Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm

              1 Reply Last reply
              0
              • R Rama Krishna Vavilala

                C++ trick of the day. As my work day was coming near to close, I was browsing to the source code of Generative Programming book.. I saw some code like this :-

                Matrix m = 1, 2, 3 ,4 ,5;

                That time I relaized that , operator can also be overloaded. I wrote something like this :-

                class dummy
                {
                public:
                std::vector vec;

                dummy& operator,(const int& val)
                {
                	vec.push\_back(val);
                	return \*this;
                }
                
                dummy& operator = (const int& val)
                {
                	vec.push\_back(val);
                	return \*this;
                }
                

                };

                int main(int argc, char* argv[])
                {
                dummy dum;

                dum = 1, 2, 3, 4, 5;
                
                for(int i = 0; i < dum.vec.size(); i++)
                {
                	cout << dum.vec\[i\];		
                }
                
                return 0;
                

                }

                This is one of the neatest tricks I have seen with C++. Simply amazing. C# is fundamentally broken. - Christian Graus

                J Offline
                J Offline
                Jim Wuerch
                wrote on last edited by
                #8

                Yah, I've seen some pretty crazy C++ overloads, case in point the MetaKit toolkit (which I've used for a while and is quite nifty). They do all sorts of stuff with commas. Jim Wuerch www.miwasoft.com Quote from my readme files: "This is BETA software, and as such may completely destroy your computer, change the alignment of the planets and invert the structure of the universe."

                1 Reply Last reply
                0
                • J Jorgen Sigvardsson

                  Evil stuff indeed.

                  int operator,(int x, int y)
                  {
                  return x + y;
                  }

                  int main(void)
                  {
                  printf("This %d is insane!", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
                  return 0;
                  }

                  This kind of stuff could break the whole language! Are you sure you can overloard the comma operator without any restrictions? If you were another man, I would kill you where you stand! The line must be drawn here! This far, no further! They must pay for what they've done!

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #9

                  C++ goes with the theory that if you give people tools that can be used for evil, people with a reasonable level of skill will find themselves empowered to use them for good. Or as Stroustrup puts it, a language feature should not be judged by the harm it can do in the hands of an inexperienced user, but by it's usefullness when used properly. Someone should have told the C# crowd that. Christian Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

                  J 1 Reply Last reply
                  0
                  • J Jorgen Sigvardsson

                    Evil stuff indeed.

                    int operator,(int x, int y)
                    {
                    return x + y;
                    }

                    int main(void)
                    {
                    printf("This %d is insane!", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
                    return 0;
                    }

                    This kind of stuff could break the whole language! Are you sure you can overloard the comma operator without any restrictions? If you were another man, I would kill you where you stand! The line must be drawn here! This far, no further! They must pay for what they've done!

                    T Offline
                    T Offline
                    Tomasz Sowinski
                    wrote on last edited by
                    #10

                    You can't overload binary operators using built-in types only. At least one should be class/struct. Tomasz Sowinski -- http://www.shooltz.com

                    To some its a six-pack, to me it's a support group

                    J 1 Reply Last reply
                    0
                    • R Rama Krishna Vavilala

                      C++ trick of the day. As my work day was coming near to close, I was browsing to the source code of Generative Programming book.. I saw some code like this :-

                      Matrix m = 1, 2, 3 ,4 ,5;

                      That time I relaized that , operator can also be overloaded. I wrote something like this :-

                      class dummy
                      {
                      public:
                      std::vector vec;

                      dummy& operator,(const int& val)
                      {
                      	vec.push\_back(val);
                      	return \*this;
                      }
                      
                      dummy& operator = (const int& val)
                      {
                      	vec.push\_back(val);
                      	return \*this;
                      }
                      

                      };

                      int main(int argc, char* argv[])
                      {
                      dummy dum;

                      dum = 1, 2, 3, 4, 5;
                      
                      for(int i = 0; i < dum.vec.size(); i++)
                      {
                      	cout << dum.vec\[i\];		
                      }
                      
                      return 0;
                      

                      }

                      This is one of the neatest tricks I have seen with C++. Simply amazing. C# is fundamentally broken. - Christian Graus

                      K Offline
                      K Offline
                      Kannan Kalyanaraman
                      wrote on last edited by
                      #11

                      that was a neat trick, the first time I'm seeing a comma operator overloaded. Thanks for the link too. Kannan

                      1 Reply Last reply
                      0
                      • T Tomasz Sowinski

                        You can't overload binary operators using built-in types only. At least one should be class/struct. Tomasz Sowinski -- http://www.shooltz.com

                        To some its a six-pack, to me it's a support group

                        J Offline
                        J Offline
                        Jorgen Sigvardsson
                        wrote on last edited by
                        #12

                        Oh yeah, forgot about that one. The fact still remains though; you can make a virtual hell for the code maintainers. :) If you were another man, I would kill you where you stand! The line must be drawn here! This far, no further! They must pay for what they've done!

                        1 Reply Last reply
                        0
                        • C Christian Graus

                          C++ goes with the theory that if you give people tools that can be used for evil, people with a reasonable level of skill will find themselves empowered to use them for good. Or as Stroustrup puts it, a language feature should not be judged by the harm it can do in the hands of an inexperienced user, but by it's usefullness when used properly. Someone should have told the C# crowd that. Christian Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

                          J Offline
                          J Offline
                          Jorgen Sigvardsson
                          wrote on last edited by
                          #13

                          Christian Graus wrote: C++ goes with the theory that if you give people tools that can be used for evil, people with a reasonable level of skill will find themselves empowered to use them for good. Hehe, sounds like the start of an excellent sci-fi/fantasy script! Keep elaborating on this one and send a copy to a Hollywood producer.. :) But for the record, I agree with you. If you were another man, I would kill you where you stand! The line must be drawn here! This far, no further! They must pay for what they've done!

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups