L
linq936
Hi,
I have this piece code,
struct TriStr {
MyString str1;
MyString str2;
MyString str3;
TriStr(MyString s1, MyString s2, MyString s3){
this->str1 = s1;
this->str2 = s2;
this->str3 = s3;
}
TriStr& operator=(const TriStr& rhs){
this->str1 = rhs.str1;
this->str2 = rhs.str2;
this->str3 = rhs.str3;
return *this;
}
bool operator==(const TriStr& rhs){
return (this->str1.IEquals(rhs.str1)
&& (this->str2.IEquals(rhs.str2))
&& (this->str3.IEquals(rhs.str3)));
}
};
bool operator==(TriStr& rhs){
return (this->str1.IEquals(rhs.str1)
&& (this->str2.IEquals(rhs.str2))
&& (this->str3.IEquals(rhs.str3)));
}
I compile it using VC7 compiler on Windows, I get a lot of error
message, please see the messages at the end of this post.
I then find that if I add "const" to operator== argument like this,
bool operator==(const TriStr& rhs){
return (this->str1.IEquals(rhs.str1)
&& (this->str2.IEquals(rhs.str2))
&& (this->str3.IEquals(rhs.str3)));
}
Then the compiler is happy.
But I am wondering why is that?
Compile error:
c:\STL\export\stl\_algobase.c(106) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(203) : see reference to function
template instantiation '_RandomAccessIter _STL
::__find<_InputIter,_Tp>(_RandomAccessIter,_RandomAccessIter,const _Tp
&,const _STL::random_access_iterator_tag &)' being compiled
with
[
_RandomAccessIter=_STL::vector<Test::TriStr>::iterator,
_InputIter=_STL::vector<Test::TriStr>::iterator,
_Tp=Test::TriStr
]
../s\test.c(72) : see reference to function template
instantiation '_InputIter _STL::find<_STL::vector<_Tp>::iterator,MdtA
ddrGen::TriStr>(_InputIter,_InputIter,const _Tp &)' being compiled
with
[
_InputIter=_STL::vector<Test::TriStr>::iterator,
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(109) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(112) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(115) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(121) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(124) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(127) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
I have this piece code,
struct TriStr {
MyString str1;
MyString str2;
MyString str3;
TriStr(MyString s1, MyString s2, MyString s3){
this->str1 = s1;
this->str2 = s2;
this->str3 = s3;
}
TriStr& operator=(const TriStr& rhs){
this->str1 = rhs.str1;
this->str2 = rhs.str2;
this->str3 = rhs.str3;
return *this;
}
bool operator==(const TriStr& rhs){
return (this->str1.IEquals(rhs.str1)
&& (this->str2.IEquals(rhs.str2))
&& (this->str3.IEquals(rhs.str3)));
}
};
bool operator==(TriStr& rhs){
return (this->str1.IEquals(rhs.str1)
&& (this->str2.IEquals(rhs.str2))
&& (this->str3.IEquals(rhs.str3)));
}
I compile it using VC7 compiler on Windows, I get a lot of error
message, please see the messages at the end of this post.
I then find that if I add "const" to operator== argument like this,
bool operator==(const TriStr& rhs){
return (this->str1.IEquals(rhs.str1)
&& (this->str2.IEquals(rhs.str2))
&& (this->str3.IEquals(rhs.str3)));
}
Then the compiler is happy.
But I am wondering why is that?
Compile error:
c:\STL\export\stl\_algobase.c(106) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(203) : see reference to function
template instantiation '_RandomAccessIter _STL
::__find<_InputIter,_Tp>(_RandomAccessIter,_RandomAccessIter,const _Tp
&,const _STL::random_access_iterator_tag &)' being compiled
with
[
_RandomAccessIter=_STL::vector<Test::TriStr>::iterator,
_InputIter=_STL::vector<Test::TriStr>::iterator,
_Tp=Test::TriStr
]
../s\test.c(72) : see reference to function template
instantiation '_InputIter _STL::find<_STL::vector<_Tp>::iterator,MdtA
ddrGen::TriStr>(_InputIter,_InputIter,const _Tp &)' being compiled
with
[
_InputIter=_STL::vector<Test::TriStr>::iterator,
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(109) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(112) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(115) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(121) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(124) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]
c:\STL\export\stl\_algobase.c(127) : error C2678: binary '==' : no
operator found which takes a left-hand operand of
type '_STL::vector<_Tp>::value_type' (or there is no acceptable
conversion)
with
[
_Tp=Test::TriStr
]