From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3915 invoked by alias); 9 Sep 2004 08:19:35 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 3878 invoked from network); 9 Sep 2004 08:19:34 -0000 Received: from unknown (HELO hotmail.com) (64.4.35.20) by sourceware.org with SMTP; 9 Sep 2004 08:19:34 -0000 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Thu, 9 Sep 2004 01:18:28 -0700 Received: from 130.233.19.1 by by12fd.bay12.hotmail.msn.com with HTTP; Thu, 09 Sep 2004 08:18:27 GMT X-Originating-IP: [130.233.19.1] X-Originating-Email: [learning_c@hotmail.com] X-Sender: learning_c@hotmail.com From: "learning c++" To: gcc-help@gcc.gnu.org Bcc: Subject: about constructor and switch Date: Thu, 09 Sep 2004 08:19:00 -0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 09 Sep 2004 08:18:28.0207 (UTC) FILETIME=[95B937F0:01C49645] X-SW-Source: 2004-09/txt/msg00066.txt.bz2 Hi, I compiled a short code. But it does not work. There are something wrong in constructor, substr and switch. 10.11.cpp: In member function `int Expr::eval()': 10.11.cpp:28: error: switch quantity not an integer #include #include using namespace std; class Expr{ int val1, val2, value; string s1; public: Expr(const string); int eval(); void print(); }; Expr::Expr(const string s){ string::iterator iter1; for(iter1=s.begin();iter1!=s.end();iter1++){ if(!isdigit(*iter1)) val1=(int)s.substr(s.begin(),iter1-1); val2=(int)s.substr(iter1+1,s.end()); s1=*iter1; } } int Expr::eval(){ switch(s1){ case "+": value=val1+val2; return value; break; case "*": value=val1*val2; return value; break; case "-": value=val1-val2; return value; break; case "/": value=val1/val2; return value; break; } } int main(){ int output; Expr input("5+3"); output=input.eval(); cout<<"The result is: "<