error: ISO C++ forbids cast to non-reference type used as lvalue

Discussion in 'C++' started by danny van elsen, May 6, 2005.

  1. hello all,

    I have recently changed from gcc 3.3.1 to version 3.4.3.

    In the following code

    class MyClass
    {
    ...
    private:
    void * current;
    }

    void *
    MyClass::Use_Pool(long size)
    {
    void * temp;

    ////////////////////////////////////////////////////////////////////////////

    temp = current;
    (char*) current += size;
    }

    I now have the following error:

    memory_pool.cc:69: error: ISO C++ forbids cast to non-reference type used as lvalue


    what would be the best way to solve this?

    thanks, D.
     
    danny van elsen, May 6, 2005
    #1
    1. Advertising

  2. danny van elsen wrote:
    > I have recently changed from gcc 3.3.1 to version 3.4.3.
    >
    > In the following code
    >
    > class MyClass
    > {
    > ...
    > private:
    > void * current;
    > }
    >
    > void *
    > MyClass::Use_Pool(long size)
    > {
    > void * temp;
    >
    > ////////////////////////////////////////////////////////////////////////////
    >
    > temp = current;
    > (char*) current += size;
    > }
    >
    > I now have the following error:
    >
    > memory_pool.cc:69: error: ISO C++ forbids cast to non-reference type used as lvalue
    >
    >
    > what would be the best way to solve this?


    Why don't you declare 'current' to be 'char*' to begin with?

    V
     
    Victor Bazarov, May 6, 2005
    #2
    1. Advertising

  3. danny van elsen

    Pete Becker Guest

    danny van elsen wrote:
    > (char*) current += size;


    If Victor's solution isn't acceptable (although it almost certainly
    should be):

    *(char**)current += size;

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)
     
    Pete Becker, May 6, 2005
    #3
  4. Pete Becker wrote:
    > danny van elsen wrote:
    >
    >> (char*) current += size;

    >
    >
    > If Victor's solution isn't acceptable (although it almost certainly
    > should be):
    >
    > *(char**)current += size;


    Or

    (char*&)current += size;

    V
     
    Victor Bazarov, May 6, 2005
    #4
  5. danny van elsen

    Heinz Ozwirk Guest

    "Pete Becker" <> schrieb im Newsbeitrag news:...
    > danny van elsen wrote:
    > > (char*) current += size;

    >
    > If Victor's solution isn't acceptable (although it almost certainly
    > should be):
    >
    > *(char**)current += size;


    Are you sure? Shouldn't that be

    *(char**)&current += size;

    or
    (char*&)current += size;

    Heinz
     
    Heinz Ozwirk, May 7, 2005
    #5
  6. danny van elsen

    Pete Becker Guest

    Heinz Ozwirk wrote:
    > "Pete Becker" <> schrieb im Newsbeitrag news:...
    >
    >>danny van elsen wrote:
    >>
    >>> (char*) current += size;

    >>
    >>If Victor's solution isn't acceptable (although it almost certainly
    >>should be):
    >>
    >>*(char**)current += size;

    >
    >
    > Are you sure? Shouldn't that be
    >
    > *(char**)&current += size;
    >


    I'm sure.

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)
     
    Pete Becker, May 7, 2005
    #6
  7. danny van elsen

    Pete Becker Guest

    Pete Becker wrote:

    > Heinz Ozwirk wrote:
    >
    >>
    >> Are you sure? Shouldn't that be
    >>
    >> *(char**)&current += size;
    >>

    >
    > I'm sure.
    >


    However, being sure isn't necessarily the same as being right. <g>
    You're right: you need the &.

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)
     
    Pete Becker, May 7, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henrik S. Hansen
    Replies:
    2
    Views:
    51,477
    Alf P. Steinbach
    May 2, 2004
  2. Penn
    Replies:
    4
    Views:
    1,383
    =?ISO-8859-1?Q?Sch=FCle_Daniel?=
    Jan 9, 2006
  3. gamehack
    Replies:
    3
    Views:
    8,122
    gamehack
    Feb 13, 2006
  4. Florian Haag
    Replies:
    7
    Views:
    873
    Florian Haag
    Jan 24, 2007
  5. Replies:
    7
    Views:
    850
    red floyd
    Feb 5, 2008
Loading...

Share This Page