Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!brutus.cs.uiuc.edu!tut.cis.ohio-state.edu!att!dptg!ulysses!andante!alice!shopiro From: shopiro@alice.UUCP (Jonathan Shopiro) Newsgroups: comp.lang.c++ Subject: Re: New Begginer Questions. Summary: Answers Message-ID: <9874@alice.UUCP> Date: 10 Sep 89 01:07:28 GMT References: <4202@ohstpy.mps.ohio-state.edu> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 43 In article <4202@ohstpy.mps.ohio-state.edu>, SMITHJ@ohstpy.mps.ohio-state.edu writes: > I'm following this conversation with interest as I am a somewhat experienced > C programmer looking to learn C++. > > Two questions: > 1. Is the declaration type* var; common in C++ programs as opposed to type *var > and if so why. I find that it misleads one to beleave that the declaration > type* x, y; > would be interpreted as > type *x, *y; > rather than the correct > type *x, y; C++ emphasizes the type system. In C, as in C++, int* is a type, but we think it more important to say that the variable pi is an int*, as in int* pi; than to say that the expression *pi is an int, as in int *pi; Of course the syntax we inherit from C makes multiple declarations treacherous, as you note, so we generally only declare one variable at a time. > 2. Why the addition of the typecast convention type(var) when (type)var > already exists. We have extended the notion of casting to allow constructing a new value from arguments. For example, you might define a type Complex to represent complex numbers, and allow construction of a Complex from one or two floats. You might then write float p, q; // :-) (Complex)p; // cast using old syntax but you have to use the new syntax for Complex(p, q); -- Jonathan Shopiro AT&T Bell Laboratories, Warren, NJ 07060-0908 research!shopiro (201) 580-4229