| 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**)¤t +=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**)¤t += 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**)¤t += 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
.
|
|
|
|

|
Related Articles |
|
|