0
#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;
}

これはこれまでの私のコードです。クラス内の関数の定義は省略しました。問題がそこにあるようには見えないからです。コンパイルしようとすると、コンパイラに次のエラーが表示されます

lvalue required as left operand of assignment. 

何を言おうとしているのかわからない。

nPointer->enterStrtPrc()=infoClass.enterStrtPrc();
nPointer->enterSellVal()=infoClass.enterSellVal();

int 値を返し、動的に作成されたクラスに格納することになっていますinfoClass

4

2 に答える 2

2

参照を返すようにメンバー関数を変更します。

struct CBAY_ITEM
{
    string & enterName();
    string & enterCondition();
    int & enterStrtPrc();
    int & enterSellVal();
};

(また、アクセス制御を正しく行います。)

于 2013-04-27T23:15:36.190 に答える
0

nPointer->enterStrtPrc() は右辺値を返す式です。数字の 5 を言ってください。それに代入することはできません。5=infoClass.enterStrtPrc();

@Kerrek SBが提案したように、戻り値の型を参照に変更すると、必要な値を入れることができるストレージが返されます。

于 2013-04-27T23:19:31.737 に答える