Path: utzoo!attcan!uunet!zephyr.ens.tek.com!uw-beaver!mit-eddie!bloom-beacon!eru!luth!sunic!sics.se!sics.se!roland From: roland@sics.se (Roland Karlsson) Newsgroups: comp.std.c++ Subject: Variable number of arguments in a method Message-ID: <1990Aug1.073606.25578@sics.se> Date: 1 Aug 90 07:36:06 GMT Sender: news@sics.se Followup-To: comp.lang.c++ gnu.g++ Distribution: comp Organization: Swedish Institute of Computer Science, Kista Lines: 38 In c++ you can have a variable number of arguments. When you declare a method you can also give default values. When using the method you can then omit zero or more arguments, starting from right to left. You can also have several methods with with same name and different number of arguments. This is CONFUSING. And there IS a far better way of doing it. Take a look at Prolog. A method (called predicate) is identified by its name and number of arguments (called arity). If you want to call a predicate and do not care about what argument to use you just write '_' (called anonymous variable). Declare method: int dummy(int a=0, int b=0, int c=100) { .... }; int dummy(int a=0) { .... }; Use method: a = x->dummy(34,45,60); b = x->dummy(34,45,_); c = x->dummy(34,_,60); d = x->dummy(_,45,60); e = x->dummy(_,_,_); f = x->dummy(12); e = x->dummy(_); This way you will not be confused by varying number of arguments, not to mention ambiguous use when declaring both methods with same name and methods with default parameters. You will also get rid of the restriction that default arguments can be removed ONLY from right to left. If you (argh) keep the old syntax and add this you will be backward compatible. But if someone use the old syntax there will be the same problems as today. Is there any hope that c++ will do this right???? -- Roland Karlsson SICS, PO Box 1263, S-164 28 KISTA, SWEDEN Internet: roland@sics.se Tel: +46 8 752 15 40 Ttx: 812 61 54 SICS S Fax: +46 8 751 72 30