Path: utzoo!attcan!uunet!husc6!mailrus!nrl-cmf!ames!lll-tis!oodis01!uplherc!utah-gr!stride!clindh
From: clindh@Stride.COM (Christer Lindh)
Newsgroups: comp.lang.c++
Subject: Two questions
Keywords: varargs
Message-ID: <798@stride.Stride.COM>
Date: 10 Jun 88 00:30:23 GMT
Organization: MicroSage Computer Systems, Reno, NV
Lines: 74

Does anyone know this?  I can't find this
information in the C++ book, but I may have missed something:

1)
   I want to define overloads to a function Print (used for a interface
   to curses), it can either take;
	a) one character,
        b) a character pointer, or
	c) a character pointer *and* a variable number of other arguments
	   (because I don't want to call the function that uses varargs
            unless it needs to be printed with printf)

   I came up with this:

   // class-definitions and stuff
   public:

     void Print(char c)        { waddch (w,c); }
     void Print(char* s)       { waddstr(w,s); }
     void Print(char* ...);    // Function that uses varargs
   // end of class

  But GNU C++ can't distinguish between the two last declarations, it
  thinks that is ambigious. I tried it on AT&T C++ as well, and this
  example compiles, but if I remove the first line ( Print(char c) ),
  it fails with "two declarations of Print()"!  Bug or feature??

  The definition for ellipis (r.8.4, C++ Programming Language):

	 "the number of arguments is known to be *equal to or
 	 greater* than the number of argument types specified"

  but what I want is a type of ellipsis that means:

	   "the number of arguments is known to be *greater*
	     than the number of argument types specified"

  Is there anyway to do this ?  I've tried Print(char *, ...) which
  makes sense to me but that gave the same result.

2)
  In an inline function with variable number of arguments, is there a
  way to reference the variable part, ie how can I pass them on to the
  function that knows about varargs ? I would like to do something
  like this:
						
  // class definitions ...
	void Print(char* fmt ... ) { wprintw( w, fmt, ... ); }
						      ^
						      |
		  		      I want to put the rest of 
			              the arguments here, but how
				      do I name them ?
  // end of class
 
  I don't want to mess with varargs in the in-line code as wprintw()
  knows how to deal with variable number of arguments. I want:

	Print("Foo %d %d %d\n", 1, 2, 3);

  to be expanded to this inline code:

	wprintw( this->w, "Foo %d %d %d\n", 1, 2 3);


  It can't be done with the standard C preprocessor, but I hope C++ is
  better.


-- 
        clindh@stride.COM        ::         The Fittest Shall Survive 
   Stride Product Group, R&D     ::           Yet The Unfit May Live. 
MicroSage Computer Systems, Inc. ::
    Reno, NV, (702) 322-6868     ::               We Must Repeat !