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



 DEVELOP > c-Plus-Plus > error: ISO C++ forbids cast to non-reference type used as lvalue

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "danny van elsen"
Date: 06 May 2005 10:36:28 AM
Object: error: ISO C++ forbids cast to non-reference type used as lvalue
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.
.

User: "Pete Becker"

Title: Re: error: ISO C++ forbids cast to non-reference type used as lvalue 06 May 2005 11:34:49 AM
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)
.
User: "Heinz Ozwirk"

Title: Re: error: ISO C++ forbids cast to non-reference type used as lvalue 07 May 2005 01:59:02 AM
"Pete Becker" <petebecker@acm.org> schrieb im Newsbeitrag =
news:v62dne_OeuQ6AebfRVn-2w@giganews.com...

danny van elsen wrote:

(char*) current +=3D size;

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

Are you sure? Shouldn't that be
*(char**)&current +=3D size;
or
(char*&)current +=3D size;
Heinz
.
User: "Pete Becker"

Title: Re: error: ISO C++ forbids cast to non-reference type used as lvalue 07 May 2005 10:19:30 AM
Heinz Ozwirk wrote:

"Pete Becker" <petebecker@acm.org> schrieb im Newsbeitrag news:v62dne_OeuQ6AebfRVn-2w@giganews.com...

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)
.
User: "Pete Becker"

Title: Re: error: ISO C++ forbids cast to non-reference type used as lvalue 07 May 2005 12:56:48 PM
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)
.



User: "Victor Bazarov"

Title: Re: error: ISO C++ forbids cast to non-reference type used as lvalue 06 May 2005 11:40:26 AM
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
.


User: "Victor Bazarov"

Title: Re: error: ISO C++ forbids cast to non-reference type used as lvalue 06 May 2005 10:53:08 AM
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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER