Operator Overloading (Bug, or error in code?)

This is a discussion on Operator Overloading (Bug, or error in code?) within the C++ Programming forums, part of the General Programming Boards category; Hey, I have this class: Code: class Integer { private: int integer; public: Integer(int nr = 0) : integer(nr){ } ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    20

    Operator Overloading (Bug, or error in code?)

    Hey,

    I have this class:

    Code:
    class Integer
    {
    	private:
    		int integer;
    
    	public:
    		Integer(int nr = 0)
    			: integer(nr){
    		}
    
    		Integer operator +(const Integer& i);
    		Integer operator -(const Integer& i);
    		Integer operator *(const Integer& i);
    		Integer operator /(const Integer& i);
    
    		Integer operator +(const int i);
    		Integer operator -(const int i);
    		Integer operator *(const int i);
    		Integer operator /(const int i);
    
    		friend Integer operator +(int d, const Integer& i)
    		{
    			return Integer(d + i.integer);
    		}
    
    		friend Integer operator-(int d, const Integer& i)
    		{
    			return Integer(d + i.integer);
    		}
    
    		friend Integer operator *(int d, const Integer& i)
    		{
    			return Integer(d * i.integer);
    		}
    
    		friend Integer operator /(int d, const Integer& i)
    		{
    			return Integer(d / i.integer);
    		}
    
    		string print();
    		void check();
    };
    When I run it I get this error:

    C:\Documents and Settings\Shady\Mijn documenten\Study\CInteger\Integer.cpp(32) : fatal error C1001: INTERNAL COMPILER ERROR
    (compiler file 'msc1.cpp', line 1786)
    Please choose the Technical Support command on the Visual C++
    Help menu, or open the Technical Support help file for more information
    Error executing cl.exe.

    When I delete the overloaded 'Minus' operator, it works just fine. Is this a bug, or is there an error in my code ?

    I'm using VC6

    Thanks in advance

    PS: print() and check() implementations are later in the code.

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    1. put friend in front of the declarations
    2. define functions outside of class

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    20
    But it's only the - Operator, and I tested it in Dev-Cpp and there it compiles with no errors.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. plez where is the bug?? here is the code
    By jaxlle in forum C Programming
    Replies: 6
    Last Post: 12-28-2006, 01:15 AM
  2. CODE Tags script bug
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 10-15-2006, 02:18 PM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 11:38 AM
  4. Bug in Code
    By bigpmc in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2004, 04:51 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21