On May 24, 8:01 pm, "John Speth" <johnsp...@yahoo.comwrote:
I have what is a simple understanding problem with c++. I just can't seea
way to reference the base class data properly in my code. Here's my simple
code that is written in MFC:
class CStringTrim : public CString
{
void Trim(void)
{
// Strip comments
int n = Find('#');
if(n != -1) *this = Left(n);
// Clean the line
TrimLeft();
TrimRight();
}
};
I simply want to have Trim() discard a string comment (#) and then trim
leading and trailing whitespace and leave the resultant string data in
place. My problem is I don't know how to refer to base class' string value
Normally, you can only do so by using the member functions of
the base class.
(see my failed attempt at using "*this").
The only reason this probably failed is that Left returns a
CString, and not a CStringTrim. You can either provide a member
operator=( CString const& ) in your own class, or cast this up
to a CString*. Or call the operator= function explicitly:
CString::operator=( Left( n ) ) ;
Off hand, however, I rather suspect that CString was not
designed to be used as a base class, and that deriving from it
is not very good design. Is there any reason why a free
function, trimComment, wouldn't do the trick. (That's certainly
the route I'd go with std::string.)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34