Posted By: Neuromancer (... bright eyes ...) on 'CZprogram'
Title: Re: C++ const
Date: Fri Sep 21 18:51:33 2001
> {
> Ptr p;
> const_holder x = p.getdata();
> }
>
> Pokus o preklad konci s chybou
> g++ a.cc -o a
> a.cc: In function `int main()':
> a.cc:36: conversion from `holder' to non-scalar type `const_holder'
> requested
>
> nevim, jakym zpusobem prekladac prinutit aby vzal tu const metodu getdata.
> v stl je toho plno a funguje to ikdyz mi neni jasny rozdil mezi tim,
> co delam ja a co je v STL.
>
> typicky je tam
>
>
> iterator begin() { return ... }
> const_iterator begin() const { return ... (totez co ve fci vys); }
Rozdil je IMHO v tom, ze iterator jde automaticky zkonvertit na
const_iterator. Zkus do const_holderu dodelat constructor, ktery
bere jako parametr holder...
> ale vyraz
>
> typedef vector<int> V;
> V vect;
>
> V::const_iterator = vect.begin(); // funguje bez problemu
>
> dik za napady,
> libor
>
> V::con
--------------------------------------------------------------------/
| ICQ 20529980 Neuromancer |
| Take me far away, where the dragons fly, |
/------------ leave me to my dreams, or just let me die. ------------