From owner-freebsd-questions Thu Apr 12 15:38:18 2001 Delivered-To: freebsd-questions@freebsd.org Received: from dsl-64-193-218-89.telocity.com (dsl-64-193-218-89.telocity.com [64.193.218.89]) by hub.freebsd.org (Postfix) with SMTP id 53A0337B449 for ; Thu, 12 Apr 2001 15:38:16 -0700 (PDT) (envelope-from lucas@slb.to) Received: (qmail 17680 invoked by uid 1000); 12 Apr 2001 22:38:34 -0000 Date: Thu, 12 Apr 2001 17:38:33 -0500 From: Lucas Bergman To: Ying-Chieh Liao Cc: freebsd-questions@FreeBSD.ORG Subject: Re: OT: cast int to enum in C++ Message-ID: <20010412173833.B7929@billygoat.slb.to> Reply-To: lucas@slb.to References: <20010413015404.A30645@terry.dragon2.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010413015404.A30645@terry.dragon2.net>; from ijliao@csie.nctu.edu.tw on Fri, Apr 13, 2001 at 01:54:04AM +0800 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Since your post is off-topic, please prefix the subject with "OT:". > In C, compiling following code is all ok but in C++, there's some > err msgs : > > test.cpp:12: conversion from `int' to `enum test' > > I've tried g++ -fenum-int-equiv test.cpp, but it said that this flag > is no longer supported :< what can I do ? dont suggest me to change > tmp(1) to tmp(TEST1) ... > > typedef enum { TEST1=1, TEST2=2, TEST3=3 } test; > void tmp(test argv) { return; } > int main(void) { tmp(1); } It's part of C++'s type safety. "int" doesn't have to implicitly convert to "enum anything" to help save the programmer from him/herself. First, since tmp() has declared its argument of type "test," what you're doing by calling tmp(1) is (probably) annoying and wrong-headed; it looks like it defeats the purpose of declaring an enum in the first place. However, if you insist in this course, changing tmp(1) to tmp((test) 1) works. (Oh, and make main() return an "int" for heaven's sake.) Lucas To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message