2013-04-27 3 views
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에 저장해야합니다. 당신의 멤버 함수

+1

각 사례 블록의 끝에 '중단'을 추가하십시오. 그렇지 않으면 넘어지게됩니다. –

+0

@AdrianPanasiuk thanx, 나는 모든 코딩을 마친 후에 그들을 추가 할 예정이었습니다. –

+0

즉, optionChosen == 1 일 때 먼저'case 1 :'블록의 코드가 실행되고'case 2 :'의 코드가 실행됩니다. (당신은 break를 가지지 않기 때문에 다음 case 블록을 실행하지 않는다는 것을 의미합니다) –

답변

2

변경 참조를 반환 :

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

(. 또한 액세스 제어 권한을 얻을)

+0

int CBAY_ITEM :: enterStrtPrc() { cout << "\ nEnter Starting Price :"; cin >> strtPrice; return strtPrice; }' 이제 컴파일러는 정의가 일치하지 않는다고 말합니다. 정의에서 무엇을 변경해야합니까? –

+0

@ user2086751 : 오류 ... 같은 건가요?! –

+0

이미 작동하지 않는'int CBAY_ITEM :: & enterStrtPrc()'를 시도했습니다. 죄송합니다. 저는 C++을 처음 접했습니다. –

0

nPointer-> enterStrtPrc를()를 rvalue를 반환하는 식입니다. @Kerrek SB가 제안 했으므로 반환 유형을 참조로 변경할 경우 5=infoClass.enterStrtPrc();

과 같이 합리적인 것이므로 값을 입력 할 수있는 저장소가 반환됩니다. 필요.

관련 문제