T
Tony Johansson
Hello!
I have this wrapper class Integer below that I use when testing operator
overloading. But I run into problem.
First this friend definition below that I have within class definition cause
the following compile error se below. I can't understand why.
Second in main when I for example use this I get completely wrong value in
object k. I should get 5.
int main()
{
Integer i(2);
Integer j(3);
Integer k = i+j;
cout << k.get();
return 0;
}
friend Integer operator+(int v, const Integer& i)
{
Integer local(v + i.value_);
return local;
}
Compiling...
start.cpp
c:\documents and settings\tony\com\slask\integer.h(21) : 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.
slask.exe - 1 error(s), 0 warning(s)
class Integer
{
public:
explicit Integer(int=0)
{}
int get() const
{ return value_; }
Integer operator+(const Integer& i) const
{
Integer local(value_ + i.value_);
return local;
}
friend Integer operator+(int v, const Integer& i)
{
Integer local(v + i.value_);
return local;
}
private:
int value_;
};
Integer operator+(const Integer& i, int v)
{
Integer local(v + i.get());
return local;
}
//Tony
I have this wrapper class Integer below that I use when testing operator
overloading. But I run into problem.
First this friend definition below that I have within class definition cause
the following compile error se below. I can't understand why.
Second in main when I for example use this I get completely wrong value in
object k. I should get 5.
int main()
{
Integer i(2);
Integer j(3);
Integer k = i+j;
cout << k.get();
return 0;
}
friend Integer operator+(int v, const Integer& i)
{
Integer local(v + i.value_);
return local;
}
Compiling...
start.cpp
c:\documents and settings\tony\com\slask\integer.h(21) : 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.
slask.exe - 1 error(s), 0 warning(s)
class Integer
{
public:
explicit Integer(int=0)
{}
int get() const
{ return value_; }
Integer operator+(const Integer& i) const
{
Integer local(value_ + i.value_);
return local;
}
friend Integer operator+(int v, const Integer& i)
{
Integer local(v + i.value_);
return local;
}
private:
int value_;
};
Integer operator+(const Integer& i, int v)
{
Integer local(v + i.get());
return local;
}
//Tony