473,326 Members | 2,255 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,326 software developers and data experts.

Error : Formal argument requires an lvalue

Gil
Can anyone see why I'm getting an error with the following code :

void NewData::store(NewDataStruct nd, unsigned long& NewDataID)
{
OtherData.store(nd, NewDataID); // error in this line
// error with NewDataID
}

void OtherData::store(NewDataStruct nd, unsigned long NewDataID)
{

..
..
..

}

error message is :
"src/DataObjects.cpp", line 30: Error: Formal argument _NewDataID of
type unsigned& in call to NewData::store(const NewDataStruct&,
unsigned&) requires an lvalue.
Jul 22 '05 #1
6 4774
Gil wrote:
Can anyone see why I'm getting an error with the following code :

void NewData::store(NewDataStruct nd, unsigned long& NewDataID)
{
OtherData.store(nd, NewDataID); // error in this line
// error with NewDataID
}

void OtherData::store(NewDataStruct nd, unsigned long NewDataID)
{

.
.
.

}

error message is :
"src/DataObjects.cpp", line 30: Error: Formal argument _NewDataID of
type unsigned& in call to NewData::store(const NewDataStruct&,
unsigned&) requires an lvalue.


How is your compiler expected to guess which version of store() to call
where? If you feed it things which could be used as unsigned long& or
unsigned long, how does it know which version to call?

Write only one version of the function, with either unsigned long& - meaning
you intend to change the argument, or unsigned long, meaning you don't.

--
Phlip
http://www.xpsd.org/cgi-bin/wiki?Tes...UserInterfaces

Jul 22 '05 #2

"Gil" <br**************@hotmail.com> wrote in message
news:ad**************************@posting.google.c om...
Can anyone see why I'm getting an error with the following code :

void NewData::store(NewDataStruct nd, unsigned long& NewDataID)
{
OtherData.store(nd, NewDataID); // error in this line
// error with NewDataID
}
You need to decide whether you want NewDataID to be a const unsigned long&.

The error could have occurred due to a situation like this:

int test(int& i) //error:needs to be const int& in such a case
{
return i+1;
}

int main()
{
test(2);
}

If you do need to change the value of the integer:

int test(int& i)
{
i=100;
return i;
}

int main()
{
int j=34;
test(j);
}
Regards,
Sumit.
void OtherData::store(NewDataStruct nd, unsigned long NewDataID)
{

.
.
.

}

error message is :
"src/DataObjects.cpp", line 30: Error: Formal argument _NewDataID of
type unsigned& in call to NewData::store(const NewDataStruct&,
unsigned&) requires an lvalue.

Jul 22 '05 #3
Gil wrote in news:ad**************************@posting.google.c om:
Can anyone see why I'm getting an error with the following code :

void NewData::store(NewDataStruct nd, unsigned long& NewDataID)
{
Whats OtherData here, you use it like its an variable identifier
but later I see its a class name.

Did you mean to write:

OtherData::store( nd, NewDataID );
OtherData.store(nd, NewDataID); // error in this line
// error with NewDataID
}

void OtherData::store(NewDataStruct nd, unsigned long NewDataID)
{

.
.
.

}

error message is :
"src/DataObjects.cpp", line 30: Error: Formal argument _NewDataID of
type unsigned& in call to NewData::store(const NewDataStruct&,
unsigned&) requires an lvalue.


The above message contains:

NewData::store(const NewDataStruct&, unsigned&);

Which is *not* a declaration you've shown us. It might help
if you copy (cut & paste) the actual code into your message, then
remove the unnessasery details.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #4
Phlip wrote:

Gil wrote:
Can anyone see why I'm getting an error with the following code :

void NewData::store(NewDataStruct nd, unsigned long& NewDataID)
{
OtherData.store(nd, NewDataID); // error in this line
// error with NewDataID
}

void OtherData::store(NewDataStruct nd, unsigned long NewDataID)
{

.
.
.

}

error message is :
"src/DataObjects.cpp", line 30: Error: Formal argument _NewDataID of
type unsigned& in call to NewData::store(const NewDataStruct&,
unsigned&) requires an lvalue.


How is your compiler expected to guess which version of store() to call
where? If you feed it things which could be used as unsigned long& or
unsigned long, how does it know which version to call?


You may have missed, that both store functions belong to different
classes acoriding to the posted code.

On the other hand, the posted error message doesn't fit with that.
More info from the OP is needed.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #5

"Gil" <br**************@hotmail.com> skrev i en meddelelse
news:ad**************************@posting.google.c om...
Can anyone see why I'm getting an error with the following code :

void NewData::store(NewDataStruct nd, unsigned long& NewDataID)
{
OtherData.store(nd, NewDataID); // error in this line
// error with NewDataID
}

void OtherData::store(NewDataStruct nd, unsigned long NewDataID)
{

.
.
.

}

error message is :
"src/DataObjects.cpp", line 30: Error: Formal argument _NewDataID of
type unsigned& in call to NewData::store(const NewDataStruct&,
unsigned&) requires an lvalue.


The code above is okay. You must have made an error when doing cut&paste.
This also explains the error-message, where the signature of NewData::store
differs from that of the example.

Kind regards
Peter
Jul 22 '05 #6
Gil
First off, Thanks very much every one for all the helpful feedback!!

I changed the code to remove unnecessary details, but I think the code
was changed in the translation.

More accurate :

void NewData::store(NewDataStruct nd, unsigned long& NewDataID)
{
od.store(nd, NewDataID); // error in this line
// error with NewDataID
// od is an instantiation of OtherData
// od is private to NewData
}

void OtherData::store(NewDataStruct nd, unsigned long NewDataID)
{

..
..
..

}

The code in question actually compiles without error on Microsoft
Visual C++ 6.0. But I get the error when compiling with SunC++ 5.4.
At first I thought the error might be because I am passing NewDataID
into NewData::store by reference and then am passing this into
od.store not as a reference. Could that cause the error? NewData and
OtherData are two different classes. I want the parameter NewDataID to
be changed in NewData, but not in OtherData. The error message was
strange in that it didn't seem to fit with the code I had. Maybe I
should put more of the actual code in.
Jul 22 '05 #7

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

Similar topics

1
by: Azzedine | last post by:
Dear All, I compiled a project under Unix, I have got the following errors: ------------------------------------------ CC -I. -DUNIX -c XPCFileStat.C -g -o XPCFileStat.o "XPCFileStat.C",...
7
by: Matthew Del Buono | last post by:
Don't try to solve the problem. I've found a way -- around or fixing it. I'm just curious as to whether this is Microsoft's problem in their compiler or if there's a standard saying this is to be...
12
by: RoSsIaCrIiLoIA | last post by:
On Mon, 07 Feb 2005 21:28:30 GMT, Keith Thompson <kst-u@mib.org> wrote: >"Romeo Colacitti" <wwromeo@gmail.com> writes: >> Chris Torek wrote: >>> In article <4205BD5C.6DC8@mindspring.com> >>>...
8
by: - | last post by:
Hi to All, To reproduce: The expression: object result = flag ? (long) 0 : (double) 0; always evaluated as a double... see dissassembly to ensure the bad compiled code.
14
by: Akhil | last post by:
plz c d following code #include<stdio.h> void main() { int x=4,y=1; y=x++++; //gives error message lvalue required y=x++ + ++y;//no errors
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
22
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float...
10
by: subramanian100in | last post by:
consider the following program: #include <iostream> using namespace std; class my_complex { public: friend ostream & operator<<(ostream &os, const my_complex &c);
63
by: Kapteyn's Star | last post by:
Hi newsgroup The program here given is refused by GCC with a error i cannot understand. It says rnd00.c: In function ‘main’: rnd00.c:26: error: expected expression before ‘]’ token ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.