Dominique wrote in news:Ynjlb.28629$Ol.566819@read1.cgocable.net:
[color=blue]
> Hi
>
> Can anyone help here. I have defined a copy constructor:
>
> CString::CString (const CString &string) // copy constructor
> {
> Int16 size = string.GetLength() + 1; // this line generates error
> ...
> }
>
> and the GetLength member:
>
> Int16 CString::GetLength()[/color]
Int16 CString::GetLength() const[color=blue]
> {
> ...
> }
>[/color]
change the declaration in your CString class too;
class CString
{
// was Int16 CString::GetLength();
Int16 CString::GetLength() const;
};
[color=blue]
> The error on the marked line is:
>
> const CString as 'this' argument of 'Int16 CString::GetLength()'
> discards qualifiers[/color]
the qualifier here is the const applied to the argument of your
copy-ctor.
[color=blue]
>
> I am using the GCC compiler, and I assume the 'const' is the source of
> the problem, but everywhere I look, the copy constructor seems to be
> defined correctly.
>
> Is this a problem in the compiler, or have I made an error?
>[/color]
The compilers right this time.
HTH
Rob.
--
http://www.victim-prime.dsl.pipex.com/