Topic: const iterator cast problem


Author: "=?iso-8859-1?B?WXXhbiBC8w==?=" <yuanbo@nus.edu.sg>
Date: 1998/06/11
Raw View
This is a multi-part message in MIME format.

------=_NextPart_000_0005_01BD955B.5FA87500
Content-Type: text/plain;
 charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

I use Borland C++ 5.02 to compile the following tiny program, and it =
complains!

[program]

#include <list>

struct B : public std::list<int>
{
    B(const B& b)
    {
        for (iterator i(b.begin()); i !=3D b.end(); ++i);
    }
};

main()
{
    return 0;
}

[complaint]

Could not find a match for 'std::list<int>::iterator::iterator(
std::list<int>::const_iterator)' in function B::B(const B &)

What does it mean? I'd request the help of your sharp eyes. Many thanks!

Bo

------=_NextPart_000_0005_01BD955B.5FA87500
Content-Type: text/html;
 charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.2106.6"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"" size=3D2><FONT =
face=3DCourier>Hi,</FONT></FONT><FONT=20
face=3DCourier></FONT></DIV>
<DIV><FONT face=3D"" size=3D2><FONT face=3DCourier></FONT></FONT><FONT=20
face=3DCourier></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"" size=3D2><FONT face=3DCourier>I use Borland C++ =
5.02 to compile=20
the following tiny program, and it complains!</FONT></FONT><FONT=20
face=3DCourier></FONT></DIV>
<DIV><FONT face=3D"" size=3D2><FONT face=3DCourier></FONT></FONT><FONT=20
face=3DCourier><FONT color=3D#000000 face=3D"" =
size=3D2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><A=20
href=3D"file://---------------- program -------------------"><FONT=20
face=3DCourier>[program]</A></FONT></FONT><FONT =
face=3DCourier></FONT></DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT =
face=3DCourier></FONT></FONT><FONT=20
face=3DCourier><FONT color=3D#000000 face=3D"" =
size=3D2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT =
face=3DCourier>#include=20
&lt;list&gt;</FONT></FONT><FONT face=3DCourier></FONT></DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT =
face=3DCourier></FONT></FONT><FONT=20
face=3DCourier></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT =
face=3DCourier>struct B : public=20
std::list&lt;int&gt;<BR>{<BR>&nbsp;&nbsp;&nbsp; B(const B&amp;=20
b)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
for=20
(iterator i(b.begin()); i !=3D b.end(); ++i);<BR>&nbsp;&nbsp;&nbsp;=20
}<BR>};</FONT></FONT><FONT face=3DCourier></FONT></DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT =
face=3DCourier></FONT></FONT><FONT=20
face=3DCourier></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT=20
face=3DCourier>main()<BR>{<BR>&nbsp;&nbsp;&nbsp; return=20
0;<BR>}<BR></FONT></FONT><FONT face=3DCourier></FONT></DIV>
<DIV><FONT face=3DCourier size=3D2>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><A=20
href=3D"file://---------------- complaint ------------------"><FONT=20
face=3DCourier>[complaint]</A></FONT></FONT><FONT =
face=3DCourier></FONT></DIV>
<DIV><FONT color=3D#000000 face=3D"" size=3D2><FONT =
face=3DCourier></FONT></FONT><FONT=20
face=3DCourier></FONT>&nbsp;</DIV><FONT face=3DCourier>Could not find a =
match for=20
'std::list&lt;int&gt;::iterator::iterator(<BR>std::list&lt;int&gt;::const=
_iterator)'=20
in function B::B(const B &amp;)<BR></FONT></FONT><FONT=20
face=3DCourier></FONT></DIV>
<DIV><FONT face=3D"" size=3D2><FONT face=3DCourier></FONT></FONT><FONT=20
face=3DCourier><FONT color=3D#000000 face=3D"" size=3D2>What does it =
mean? </FONT><FONT=20
face=3D"" size=3D2>I'd request the help of your sharp eyes. Many=20
thanks!</FONT></FONT></DIV>
<DIV><FONT face=3D"" size=3D2><FONT face=3DCourier></FONT></FONT><FONT=20
face=3DCourier></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier size=3D2>Bo</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01BD955B.5FA87500--
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1998/06/11
Raw View
Yu=E1n B=F3 <yuanbo@nus.edu.sg> writes:

> struct B : public std::list<int> {
> =A0=A0=A0 B(const B& b) {
> =A0=A0=A0=A0=A0=A0=A0 for (iterator i(b.begin()); i !=3D b.end(); ++i);

b.begin() returns a const_iterator, and there is no conversion from
const_iterator to iterator.  Declare `i' as const_iterator and your
problem is gone.

--=20
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]