C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Error : Formal argument requires an lvalue

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Gil
Guest





PostPosted: Fri Jan 30, 2004 2:47 pm    Post subject: Error : Formal argument requires an lvalue Reply with quote



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.
Back to top
Phlip
Guest





PostPosted: Fri Jan 30, 2004 3:00 pm    Post subject: Re: Error : Formal argument requires an lvalue Reply with quote



Gil wrote:

Quote:
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?TestFirstUserInterfaces




Back to top
Sumit Rajan
Guest





PostPosted: Fri Jan 30, 2004 3:22 pm    Post subject: Re: Error : Formal argument requires an lvalue Reply with quote




"Gil" <brightoceanlight (AT) hotmail (DOT) com> wrote

Quote:
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.

Quote:
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.



Back to top
Rob Williscroft
Guest





PostPosted: Fri Jan 30, 2004 3:59 pm    Post subject: Re: Error : Formal argument requires an lvalue Reply with quote

Gil wrote in news:adc2ca29.0401300647.13304207 (AT) posting (DOT) google.com:

Quote:
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 );

Quote:
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/

Back to top
Karl Heinz Buchegger
Guest





PostPosted: Fri Jan 30, 2004 4:02 pm    Post subject: Re: Error : Formal argument requires an lvalue Reply with quote

Phlip wrote:
Quote:

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
[email]kbuchegg (AT) gascad (DOT) at[/email]

Back to top
Peter Koch Larsen
Guest





PostPosted: Fri Jan 30, 2004 5:24 pm    Post subject: Re: Error : Formal argument requires an lvalue Reply with quote


"Gil" <brightoceanlight (AT) hotmail (DOT) com> skrev i en meddelelse
news:adc2ca29.0401300647.13304207 (AT) posting (DOT) google.com...
Quote:
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



Back to top
Gil
Guest





PostPosted: Sat Jan 31, 2004 10:39 am    Post subject: Re: Error : Formal argument requires an lvalue Reply with quote

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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.