Barry
10/12/2008 1:46:00 PM
On Oct 12, 9:05 pm, Alex Vinokur <ale...@users.sourceforge.net> wrote:
> On Oct 12, 2:22 pm, Barry <dhb2...@gmail.com> wrote:
>
>
>
> > On Oct 12, 7:16 pm, Alex Vinokur <ale...@users.sourceforge.net> wrote:
>
> > > Hi,
>
> > > Is it possible to do C++-casting from
> > > const pair<const unsigned char*, size_t>*
> > > to
> > > const pair<unsigned char*, size_t>*
> > > ?
>
> > const pair<const unsigned char*, size_t>* p1 = 0;
> > const pair<unsigned char*, size_t>* p2 =
> > reinterpret_cast<const pair<unsigned char*, size_t>*>(p1);
>
> > but reinterpre_cast should be avoided if possible.
> > *Practically*, I wonder you can just do it this way:
>
> > char* s = const_cast<char*>(p1->first);
>
> > Or can you tell me the scenario you are in?
>
> I have function foo1 (const pair<unsigned char*, size_t>* p);
> I need also function foo2 (const pair<const unsigned char*, size_t>*
> p) that does the same thing as foo1().
>
> Currently
> void foo2 (const pair<const unsigned char*, size_t>* p)
> {
> // I would like to use here C++-style casting
> const pair<unsigned char*, size_t>* p1 = ( const pair<unsigned
> char*, size_t>* ) p;
> foo1(p1);
>
> }
>
I'm sorry that my previous post misled you.
I think sam got my answer.
What I asked is that I was confused that why you need
such conversion. And I was expecting to see if there's some
way to avoid such conversion.
If you just wanted to learn the language. OK, "reinterpret_cast"
as C++-style cast, or just use C-style cast. While in practice,
avoid doing this.
--
Best Regards
Barry