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

  • Thread starter danny van elsen
  • Start date
D

danny van elsen

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.
 
V

Victor Bazarov

danny said:
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
 
V

Victor Bazarov

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

*(char**)current += size;

Or

(char*&)current += size;

V
 
H

Heinz Ozwirk

Pete Becker said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top