Thread: What is the return value for a type Class? code example

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    158

    What is the return value for a type Class? code example

    Code:
     returnType operatorOperatorSymbol (parameterList); // syntax for operator overloading
    
    
    Class Fraction
    
       public:
      Fraction operator-(const Fraction& f1)
    {
      Fraction r;
      return r;
    }
    is this even syntactically correct? It gives me errors. Im just trying to compile it without errors. I think the function makes sense since its returning a type Class

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    What kind of errors is it giving you?

    Because this works for me (this is contained in a .hpp file) :
    Code:
    inline point operator+(const point &p1, const point &p2) {
    	return point(p1.x + p2.x, p1.y + p2.y, p1.z + p2.z);
    }

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    you need brackets around your class definition.

    Code:
    class  MyClass
    {
    
    };
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class function return type
    By Justin H in forum C++ Programming
    Replies: 12
    Last Post: 12-05-2012, 07:57 PM
  2. Replies: 24
    Last Post: 04-19-2012, 04:51 AM
  3. return type
    By shuaib.akram in forum C Programming
    Replies: 2
    Last Post: 08-27-2007, 11:53 PM
  4. finding derived class type of a pointer to a base class
    By LinuxCoder in forum C++ Programming
    Replies: 15
    Last Post: 04-10-2006, 11:08 AM
  5. Replies: 6
    Last Post: 04-09-2006, 04:32 PM