Menu

operator+

2002-12-25
2012-09-26
  • Nobody/Anonymous

    Hello, my question is:
    If I write:

    int a=3, b=4, c;
    c=operator+(a, b);

    the compiler gives me the message:
    operator+ not defined

    What should I do?
    Franjo

     
    • upcase

      upcase - 2002-12-25

      Hi there!
      You are working in C++ I guess...
      1. You are calling operator+() as a free function. Normally it will be a friend or member function.
      2. I think int is not a class so calling an operator for that makes no sense.
      You could implement a new operator for a new class you wrote (like string or Int (watch case)).

       
    • Derek Baker

      Derek Baker - 2002-12-25

      Franjo,

      what's wrong with:

      c= a+ b;

      ?

      Derek

       
    • Curtis Sutter

      Curtis Sutter - 2002-12-25

      Since you are using only int's and not classes, c = a + b; should do the trick.  When you start into classes it becomes a bit harder, but would still be c = a + b;

      Curtis

       
    • Nobody/Anonymous

      First of all thanks for respnse Curtis, Derek and Rene. I already work with classes, and within the class this code works.
      Franjo

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.