Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ Infixes

  • 21-01-2002 9:56pm
    #1
    Registered Users, Registered Users 2 Posts: 2,281 ✭✭✭


    i have googled about for the last few minutes, and i can't find anything on it.

    Can you make your own custom infixes in c++?

    I have a class Vector and class quaterion and i want to be able to type:

    Vector a,b,c;
    .....
    c = a + b;

    instead of

    c = a.add(b);


Comments

  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    yeah, I think what your looking for is operator overloading.
    Something like this:
    Vector Vector::operator+ ( const Vector& v1, const Vector& v2 ){
          Vector v;
    
          v.x = v1.x + v2.x ;
          v.y = v1.y + v2.y ;
          v.z = v1.z + v2.z ;
    
          return v;
    }
    


  • Registered Users, Registered Users 2 Posts: 2,281 ✭✭✭DeadBankClerk


    Thanks a million Jazz.

    BTW the freaky thing is that your code went into mine without any editing :/

    My class Vector has 3 public doubles called x,y,z.


  • Registered Users, Registered Users 2 Posts: 2,281 ✭✭✭DeadBankClerk


    Its that darn Burtan Meyer and his eiffel that has me calling the things infixes.

    !! pling pling.


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma




  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Great minds think alike, eh? :D


  • Advertisement
Advertisement