COMPILER INTERNAL ERROR

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
using namespace std;

#define D3D_OVERLOADS
#include <d3d.h>

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

Any ideas?

semms to be an compiler error
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).]

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.

I checked it again and actually only
friend addition or substraction operator
overloading causes the error.

class WhatEver
{
public:
//…
//…

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

};

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

Help needed!

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 &x);
};
WhatEver WhatEver::operator+(const WhatEver &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).]

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 &str2);
};

string operator +(char * str1, const string &str2)
{
//…
}

is perfectly valid.

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

WhatEver SomeFunction(const WhatEver &w1,
const WhatEver &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 &w1, WhatEver &w2)
{
WhatEver ret;
//some other operation
//…
//…
ret = w1 + w2;
return ret;
}

But I’m just curious why this can cause error

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 ?

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.

Well, Burner, I tested your code above, and it compiled with no errors using MSVC++ 6.0 (SP4)

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.

It seem like it’s my compiler’s problem.
Thanks anyway.

Originally posted by Questions Burner:

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

[quote]

WhatEver SomeFunction(const WhatEver &w1,
const WhatEver &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.

[/QUOTE]

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

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

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

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.

Originally posted by dslater:
[b] [quote]

WhatEver SomeFunction(const WhatEver &w1,
const WhatEver &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 &w);
whatever operator +(const whatever &w)const;
};

This will allow you to have bothe sides of the + operator be const[/b][/QUOTE]

Thanks