Internal compiler error

This is a discussion on Internal compiler error within the C++ Programming forums, part of the General Programming Boards category; i have a certain problem regarding operator overloading function ....when i implement the overloading functions as friend functions i get ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    2

    Wink operator overloading functions Problem

    i have a certain problem regarding operator overloading function ....when i implement the overloading functions as friend functions i get the same
    INTERNAL COMPILER ERROR ...what does that mean??? the program is free of syntax errors...but it is not working. How can i solve this problem??


    the program...

    Code:
    #include <iostream>
    
    using namespace std;
    
    class s1
    {
    	friend s1 operator+(int ,const s1 &);
    public:
    	s1()   { x=9;  y=3; }
    	s1( int i)   {x=i;  y=7; }
    	s1( int i, int j)   { x=i;  y=j; }
    	void print()   { cout<<x<<"  "<<y<<endl; }
    	s1 operator+(const s1 &k) const
    	{
    		s1 M;
    		M.x=this->x+k.x;
    		M.y=this->x+k.y;
    		return M;
    	}
    	
    private:
    	int x, y;
    };
    
    s1 operator+(int x,const s1 &A )
    {
    	s1 F;
    	F.x=A.x+x;
    	F.y=A.y+x;
    	return F;
    }
    		
    void main()
    {
    	s1 T, T2(5), T3(-1, 4);
    
    	T.print();  T2.print();  T3.print();
    
    	T=T2+T3;
    
    	T.print();
    
    	s1 T4=5+T3;
    
    	T.print();
    	T2.print();
    	T3.print();
    	T4.print();
    }
    //note: when i implement the operator overloading function as member function the program runs smoothly.
    Last edited by Salem; 12-10-2007 at 06:05 AM. Reason: [code][/code] tags around the CODE only! oh, and split the thread

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    @ comptuer_nerd: Your subject is PROBABLY completely different, so I would suggest that one of the moderators split this out into it's own thread.

    In the meantime, I have no idea why you are getting an internal compiler error, but I can say that your code compiles (and runs) just fine with gcc 3.4.2 [at least, it manages to complete running the code without crashing - I haven't attempted to check the results as such].

    "Internal compiler error" is just that - it means that something inside the compiler went wrong. This can be caused by many different things, and it can be caused by as simple things as a syntax error, but more likely by doing something "unexpected" in the compiler writers view.

    By the way, you should use "int main()", not "void main()" - as the latter is unportable and can lead to "strange" effects.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    IF you get an internal compiler error, usually a rebuild solves that problem, unless you're using a very crappy compiler.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Internal Compiler Error is just the compiler's way of saying "Hi, I'm a piece of crap!".
    I would guess that the compiler in this case is VS6. If so, time to upgrade.

    You shouldn't be defining operator + as a member function if you want the left-hand side to be able to be a non class instance. Try declaring it in the two-parameter 'friend' form, or as a free function. The second form of operator + you wrote will then automatically work by making use of your int constructor.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    Quote Originally Posted by iMalc View Post
    Internal Compiler Error is just the compiler's way of saying "Hi, I'm a piece of crap!".
    Not always. C++ is a very complex language so obviously a compiler is a very complex piece of software too. I've gotten about 2-3 internal errors in Visual Studio 2005 I think. Sometimes the compiler gets confused. A rebuild always helps this.
    If it doesn't help, then it's probably a bad compiler.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I found that if you're using MS VC++ 6.0 and you get some strange problem, just delete the .ncb project file and do a "Rebuild All".

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Sounds like a real compiler bug. The code is simple enough and there is nothing wrong with it that I can see.

    Start removing single lines of code at a time until the error goes away. Then you'll know what causes it. Like you suspect it probably has to do with that friend operator.

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by Elysia View Post
    Not always. C++ is a very complex language so obviously a compiler is a very complex piece of software too. I've gotten about 2-3 internal errors in Visual Studio 2005 I think. Sometimes the compiler gets confused. A rebuild always helps this.
    If it doesn't help, then it's probably a bad compiler.
    Now you've gone and exposed my intentional half-truth. I know, it isn't always because the compiler is bad. I've had this happen many times in VS2005 when there are bugs in complex template meta-programming code. However since this code is very simple I find it extremely unlikely that it is from any relatively recent compiler.
    I didn't mention that other compilers can also still generate this error because I didn't want to distract from the point I was going to make once the compiler was confirmed (as presumably VS6), that it is a piece of crap!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    VS6 is a piece of crap, yes. And if a compiler can't handle such easy code, then it's probably a crap compiler too. Yup, you're probably right.
    CoMpuTer NerD - so try a rebuild and see if it helps. Otherwise I really do suggest another compiler.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    And don't forget to try deleting your .ncb file & Rebuild All. When I used VC++ 6 I sometimes found that I could Rebuild all day long and it wouldn't help in some situations unless I deleted the .ncb file which tends to get corrupt at least once a day.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 02:29 PM
  2. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  3. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 10:09 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 11:52 PM

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