class cid
{
int caseNo,agentNo;
public:
cid(){}
cid(int caseNo)
{
this->caseNo = caseNo;
}
void operator<<(int x)
{
this->agentNo = x;
}
void operator>>(int x)
{
this->agentNo = 0;
if(x == this->caseNo)
cout << "\nhello";
else
cout << "\nbye";
}
void display(void)
{
cout << "\ncase num is : " << caseNo << " agent num is : " << agentNo;
}
};
int main()
{
cid daya(1),praduman(7);
daya << 10;
praduman << 1550;
daya.display();
praduman.display();
daya >> 10;
praduman >> 1550;
daya.display();
praduman.display();
cout << "\npress enter to continue...";
cin.ignore();cin.get();
return 0;
}
输出
case num is : 1 agent num is : 10
case num is : 7 agent num is : 1550
bye
bye
case num is : 1 agent num is : 0
case num is : 7 agent num is : 0
press enter to continue...
我试图评估caseNo和x以查看它是否被分配,如果数字相同然后使agentNo为0但是调试我试图将它与1进行比较,因为已经分配为案例编号,它评估为false plz帮助
答案 0 :(得分:0)
排队
cid daya(1),praduman(7);
您设置了daya.caseNo = 1
和praduman.caseNo = 7
。与
daya << 10;
praduman << 1550;
您设置了daya.agentNo = 10
和praduman.agentNo = 1550
。这正是
daya.display();
praduman.display();
使用daya >> 10;
设置daya.agentNo = 0
并检查是否if(x == this->caseNo)
。 x
的值为10,daya.caseNo
为1
。因此,这会产生false
并输出Bye
。 praduman >> 1550;