W
William Payne
Hello, I am toying with a simple string class I wrote quite some time ago. I
noticed that if I try to use operator == or != I get undefiend references,
but I dont see why. In my class declaration I have:
bool operator==(const String& rhs) const;
bool operator!=(const String& rhs) const;
(In the public section.)
And in the implementation file of my little string class, I have:
inline bool
String:perator==(const String& rhs) const
{
return std::strcmp(m_internal_string, rhs.m_internal_string);
}
inline bool
String:perator!=(const String& rhs) const
{
return !((*this) == rhs);
}
The code that triggers these undefined references is simply:
if(str == s2)
{
cout << "s2 == str" << endl;
}
else
{
cout << "s2 != str" << endl;
}
if(str != s2)
{
cout << "s2 != str" << endl;
}
else
{
cout << "s2 == str" << endl;
}
where str and s2 is of type String (my string class).
And one more thing, if the compiler rejects:
String foo("bar");
foo[1] = c; // Doesn't like this line!
what am I missing?
Thanks for any replies!
/ WP
noticed that if I try to use operator == or != I get undefiend references,
but I dont see why. In my class declaration I have:
bool operator==(const String& rhs) const;
bool operator!=(const String& rhs) const;
(In the public section.)
And in the implementation file of my little string class, I have:
inline bool
String:perator==(const String& rhs) const
{
return std::strcmp(m_internal_string, rhs.m_internal_string);
}
inline bool
String:perator!=(const String& rhs) const
{
return !((*this) == rhs);
}
The code that triggers these undefined references is simply:
if(str == s2)
{
cout << "s2 == str" << endl;
}
else
{
cout << "s2 != str" << endl;
}
if(str != s2)
{
cout << "s2 != str" << endl;
}
else
{
cout << "s2 == str" << endl;
}
where str and s2 is of type String (my string class).
And one more thing, if the compiler rejects:
String foo("bar");
foo[1] = c; // Doesn't like this line!
what am I missing?
Thanks for any replies!
/ WP