473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.

Jul 23 '05 #1
6 6883
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
Jul 23 '05 #2
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)
Jul 23 '05 #3
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
Jul 23 '05 #4

"Pete Becker" <pe********@acm.org> schrieb im Newsbeitrag news:v6********************@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;

or
(char*&)current += size;

Heinz
Jul 23 '05 #5
Heinz Ozwirk wrote:
"Pete Becker" <pe********@acm.org> schrieb im Newsbeitrag news:v6********************@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)
Jul 23 '05 #6
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)
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gizmo | last post by:
hello all have been trying to write a Mid() function a bit like the one in vb. i come to compile it and there are no errors however when i run it an error accours and it says the program has to...
2
by: Abhijit Bhadra | last post by:
Hi , I was trying to build my project in VC with latest Service Packs but got this error . C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(125) : error C2440: 'return' :...
1
by: Edwin Quijada | last post by:
I have a trigger when I executed I get this error: WARNING: Error occurred while executing PL/pgSQL function actualizar_pagos_comisiones WARNING: line 19 at select into variables ERROR: ...
16
by: Amarendra GODBOLE | last post by:
Hi, I am a bit confused over the correct usage of memcpy(). Kindly help me clear the confusion. The linux manpage for memcpy(3) gives me the following prototype of memcpy(3): #include...
3
by: picknicker187 | last post by:
hi, the program below is supposed to read data out of a txt file into an array and the second part of the data to a linked list. 8 is the number of words, the 10 terms below represent...
13
by: param | last post by:
The following C program segfaults on 64 bit Arch., but works fine on 32 bit. int main() { int* p; p = (int*)malloc(sizeof(int)); *p = 10; return 0; }
13
by: hn.ft.pris | last post by:
Hi: I have the following simple program: #include<iostream> using namespace std; int main(int argc, char* argv){ const double L = 1.234; const int T = static_cast<const int>(L); int arr;
10
by: Wilson | last post by:
i have created a class which contains all the information needed for a program based on accounts, this is shown below. When compiled the string "word" (in function writetofile) which is initialised...
4
by: Raj | last post by:
Following is a code to print integer equivalent of a hexadecimal number. If the entered number starts with a 0x or a 0X, calculation is done after skipping these two characters. Now, this code...
2
by: MATTXtwo | last post by:
i have some experience on that thing...some logical error maybe.. coz it works perfectly on different login id that i always use.. i use store procedure and maybe it got some error in it.. please...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.