Results 1 to 3 of 3

Thread: Class operators [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004

    Class operators [RESOLVED]

    Say that we had a class, A, in which is defined as such:

    Code:
    class A
    {
    	public:
    		A& operator=(const A& rhs);
    		A operator+(const float &rhs) const;
    }
    Now this would allow us to do things such as:

    Code:
    A = A + 5;
    How could we make it so that:

    Code:
    A = 5 + A;
    would be valid?
    Last edited by Darkwraith; Jun 8th, 2004 at 08:28 PM.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    Code:
    class A
    {
    
    // ...
       friend A operator+(float f, const A& a);
    }
    
    
    A operator+(float f, const A& a)
    {
       // ....
    }
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    Thanks for all your help.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width