PDA

View Full Version : COMPILER INTERNAL ERROR



Questions Burner
12-26-2001, 05:46 AM
I have the above error message when I have friend class member function.




class WhatEver
{
public:
//....
//....
friend void SomeFunction();
};

void SomeFunction()
{
//...
}



I pretty sure it's no my fault. Because when I use D3DVECTOR in <d3d.h>. The error message also occur, pointing to friend function declaration. Try




#include <iostream>
using namespace std;

#define D3D_OVERLOADS
#include <d3d.h>

void main()
{
//....
cout<<"Size "<<sizeof(D3DVECTOR)<<endl;
}



Any ideas?

T2k
12-26-2001, 06:09 AM
semms to be an compiler error http://www.opengl.org/discussion_boards/ubb/rolleyes.gif
try to rebuild the whole project(visual c++ sometimes need this ...), or reinstall your compiler ...

[This message has been edited by T2k (edited 12-26-2001).]

Questions Burner
12-26-2001, 08:07 PM
I rebuild it many times and it's still the same. And I think reinstalling will not
help because my friend compiler also have the same error.

Questions Burner
12-26-2001, 11:17 PM
I checked it again and actually only
friend addition or substraction operator
overloading causes the error.




class WhatEver
{
public:
//...
//...

friend WhatEver operator +(const WhatEver &amp;we1, const WhatEver &amp;we2);
};

WhatEver operator +(const WhatEver &amp;we1, const WhatEver &amp;we2)
{
//...
//...
return we1;
}


Help needed!

T2k
12-27-2001, 01:19 AM
overloading a public operator, what a sense is behind this ?
and your code isnt correct, if you want an +operator for your class you would do:



class WhatEver{
public:
WhatEver operator+(const WhatEver &amp;x);
};
WhatEver WhatEver::operator+(const WhatEver &amp;x){
return this+x;
}

and i think there is no other way than this one ...

[This message has been edited by T2k (edited 12-27-2001).]

Questions Burner
12-27-2001, 11:12 PM
My code has no problem, look at d3d.h file and you'll find this kind of friend operator+
. Have you ever built string class yourself,
having




class string
{
public:
friend string operator +(char * str1,
const string &amp;str2);
};

string operator +(char * str1, const string &amp;str2)
{
//...
}

is perfectly valid.

Your code won't work if you have the following function





WhatEver SomeFunction(const WhatEver &amp;w1,
const WhatEver &amp;w2)
{
WhatEver ret;
//some other operation
//...
//...
ret = w1 + w2;
return ret;
}



You'll get "no operator which takes a
left-hand operand of type 'const class Whatever'" message.

I know I can easily solve by




WhatEver SomeFunction(WhatEver &amp;w1, WhatEver &amp;w2)
{
WhatEver ret;
//some other operation
//...
//...
ret = w1 + w2;
return ret;
}


But I'm just curious why this can cause error

T2k
12-28-2001, 01:45 AM
sure( my code wont work, it will produce an stack overflow in the compiler, because i call the operator+ in the operator+ function),
and maybe you have forgotten, that the operator '=' must be overloaded too, in cases where the standard-constructor cannot solve the '=' operation, maybe that is the problem ?

Questions Burner
12-28-2001, 06:34 AM
I didn't mean you code won't run but you'll
have error in compiling instead of stack overflow. And have you tried my code, I really want to know whether is my compiler
or everyone's compiler have that error.

DFrey
12-28-2001, 07:43 AM
Well, Burner, I tested your code above, and it compiled with no errors using MSVC++ 6.0 (SP4)

Korval
12-28-2001, 08:50 PM
Internal compiler errors, while often caused by your own code, can also mean that the compiler crashed on its own, due to some bug. So, make sure you're up-to-date on all your service packs.

Also, the reason that your "WhatEver" example didn't work the first time is because you should have declared the arguments to the + operator as const. You shouldn't ever be changing them in +, so they should be const. If they were const, then the compiler wouldn't have complained.

Questions Burner
12-29-2001, 10:58 PM
It seem like it's my compiler's problem.
Thanks anyway.

dslater
12-30-2001, 06:40 AM
Originally posted by Questions Burner:

Your code won't work if you have the following function





WhatEver SomeFunction(const WhatEver &amp;w1,
const WhatEver &amp;w2)
{
WhatEver ret;
//some other operation
//...
//...
ret = w1 + w2;
return ret;
}



You'll get "no operator which takes a
left-hand operand of type 'const class Whatever'" message.



True, However, you can handle the const case liek this:




class whatever
{
public:
whatever operator +(const whatever &amp;w);
whatever operator +(const whatever &amp;w)const;
};



This will allow you to have bothe sides of the + operator be const

dslater
12-30-2001, 06:42 AM
Originally posted by Questions Burner:
It seem like it's my compiler's problem.
Thanks anyway.

Try adding a /Bd switch to the compiler command line. This causes the preprocessor and compile steps to happen as two seperate steps. Sometimes this will give you more information and sometimes, the crash just goes away.

Questions Burner
01-01-2002, 07:03 PM
Originally posted by dslater:




WhatEver SomeFunction(const WhatEver &amp;w1,
const WhatEver &amp;w2)
{
WhatEver ret;
//some other operation
//...
//...
ret = w1 + w2;
return ret;
}



You'll get "no operator which takes a
left-hand operand of type 'const class Whatever'" message.

<HR></BLOCKQUOTE>

True, However, you can handle the const case liek this:




class whatever
{
public:
whatever operator +(const whatever &amp;w);
whatever operator +(const whatever &amp;w)const;
};



This will allow you to have bothe sides of the + operator be const

Thanks http://www.opengl.org/discussion_boards/ubb/smile.gif