Reputation:
#include <iostream>
using namespace std;
string itmCndtn,itemName;
int strtPrice,sellValue,numRelist,optn=0;
class CBAY_ITEM
{
string enterName();
string enterCondition();
int enterStrtPrc();
int enterSellVal();
};
CBAY_ITEM infoClass;
CBAY_ITEM *nPointer=NULL;
int main()
{
int optionChosen=0;
int strtPrcTemp=0,sellValueTemp=0;
do
{
cout << "\nPlease Enter a Choice From the Menu.\n"<<endl;
cout << "\n1.Add an Item to Selling Queue.\n2.Put Item for Sale.\n3.Show Me the Money.\n4.Exit." << endl;
cin>>optionChosen;
switch(optionChosen)
{
case 1:
{
nPointer=new CBAY_ITEM;
nPointer->enterName()=infoClass.enterName();
nPointer->enterCondition()=infoClass.enterCondition();
nPointer->enterStrtPrc()=infoClass.enterStrtPrc();
nPointer->enterSellVal()=infoClass.enterSellVal();
}
case 2:
{
}
case 3:
{
}
}
}while(optionChosen!=4);
return 0;
}
This is my code so far, I omitted the definition of the functions within the class as it doesn't seem like thats where the problem is. When I try to compile, compiler shows an error saying
lvalue required as left operand of assignment.
I am not sure what it is trying to say.
nPointer->enterStrtPrc()=infoClass.enterStrtPrc();
nPointer->enterSellVal()=infoClass.enterSellVal();
are supposed to return int values and store them in the dynamically created class infoClass
.
Upvotes: 0
Views: 1722
Reputation: 477000
Change your member functions to return references:
struct CBAY_ITEM
{
string & enterName();
string & enterCondition();
int & enterStrtPrc();
int & enterSellVal();
};
(And also get the access control right.)
Upvotes: 2
Reputation: 21595
nPointer->enterStrtPrc() is an expression that returns rvalue. say the number 5. you cannot assign into it - it's as sensible as 5=infoClass.enterStrtPrc();
if you'll change the return types to reference, as @Kerrek SB suggested, it will return the storage in which you can put the values you want.
Upvotes: 0