From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16469 invoked by alias); 9 Sep 2004 11:54:54 -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 16414 invoked from network); 9 Sep 2004 11:54:52 -0000 Received: from unknown (HELO psmtp.com) (12.158.35.212) by sourceware.org with SMTP; 9 Sep 2004 11:54:52 -0000 Received: from source ([192.150.22.8]) by exprod6ob2.obsmtp.com ([12.158.35.250]) with SMTP; Thu, 09 Sep 2004 04:54:49 PDT Received: from inner-relay-1.corp.adobe.com (inner-relay-1 [153.32.1.51]) by smtp-relay-8.adobe.com (8.12.10/8.12.10) with ESMTP id i89BsTbA007374; Thu, 9 Sep 2004 04:54:34 -0700 (PDT) Received: from iplan-mn (iplan-mn.corp.adobe.com [130.248.25.5]) by inner-relay-1.corp.adobe.com (8.12.9/8.12.9) with ESMTP id i89BsSTk007200; Thu, 9 Sep 2004 04:54:29 -0700 (PDT) Received: from mn-eljay-a51m.adobe.com ([130.248.178.70]) by iplan-mn.corp.adobe.com (iPlanet Messaging Server 5.2 HotFix 1.21 (built Sep 8 2003)) with ESMTP id <0I3R003I9VQQR8@iplan-mn.corp.adobe.com>; Thu, 09 Sep 2004 06:54:27 -0500 (CDT) Date: Thu, 09 Sep 2004 11:54:00 -0000 From: Eljay Love-Jensen Subject: Re: about constructor and switch In-reply-to: X-Sender: eljay@iplan-mn.corp.adobe.com To: learning c++ , gcc-help@gcc.gnu.org Message-id: <6.1.2.0.2.20040909064722.02eafe78@iplan-mn.corp.adobe.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-transfer-encoding: 7BIT References: X-SW-Source: 2004-09/txt/msg00070.txt.bz2 Hi, The switch C/C++ construct can only take an integer. It cannot take an object (unless that object is convertible to an integer). Thus, it cannot take a std::string. It cannot take a float, double, long double. Or a complex. Or a pointer. It can take a char, short, int, long or bool, or any expression which evaluates to such. Some languages, such as Ada, have a more capable switch construct, which can handle those other situations that C/C++ cannot. For those more complicated situations in C/C++, use a if/else if/else construct, or use polymorphism (where applicable). HTH, --Eljay