Topic: Methods with variable number arguments like printf - Legal ?


Author: James Kanze <james-albert.kanze@vx.cit.alcatel.fr>
Date: 1997/01/03
Raw View
jlilley@empathy.com (John Lilley) writes:

|>  Morten M. Christensen wrote:
|>  > Is it legal in standard C++ to have methods with a variable
|>  > number of arguments like printf ? I.e. Are the methods below
|>  > legal ?
|>  >
|>  > class X                // An example:
|>  > {
|>  >  public:
|>  >  void printf(...);     // Accepted by BC++ and Visual C++
|>  >  void operator()(...); // Accepted by BC++, Visual C++ "crashes" on
|>  > this.
|>  > };
|>
|>  The may96 draft standard says that "..." is valid for normal methods and
|>  functions.  I assume it is valid for operator(), because default
|>  arguments are explicitly allowed, and "..." is not explicitly
|>  disallowed.  Note that "..." is not valid for operator[] or conversion
|>  operators.

Question: is "..." valid for any operator other than operator()?  I
don't think that the draft makes an explicit statement, but all other
operators do require a fixed number of parameters (1 or 2), so this
would seem to rule it out.

--
James Kanze         home:     kanze@gabi-soft.fr        +33 (0)3 88 14 49 00
                    office:   kanze@vx.cit.alcatel.fr   +33 (0)1 69 63 14 54
GABI Software, Sarl., 8 rue des Francs Bourgeois, F-67000 Strasbourg, France
       -- Conseils en informatique industrielle --
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: jlilley@empathy.com (John Lilley)
Date: 1997/01/02
Raw View
Morten M. Christensen wrote:
> Is it legal in standard C++ to have methods with a variable
> number of arguments like printf ? I.e. Are the methods below
> legal ?
>
> class X                // An example:
> {
>  public:
>  void printf(...);     // Accepted by BC++ and Visual C++
>  void operator()(...); // Accepted by BC++, Visual C++ "crashes" on
> this.
> };

The may96 draft standard says that "..." is valid for normal methods and
functions.  I assume it is valid for operator(), because default
arguments are explicitly allowed, and "..." is not explicitly
disallowed.  Note that "..." is not valid for operator[] or conversion
operators.

In the second case, I would guess that MSVC++ has trouble with the
overload resolution involving operator()(...).  MSVC++ 4.2, and probably
most C++ compilers are remarkably fragile when it comes to compiling
anything-but-plain-vanilla C++.

john lilley
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: "Morten M. Christensen" <mmc@dit.ou.dk>
Date: 1996/12/19
Raw View
Hi,

Is it legal in standard C++ to have methods with a variable
number of arguments like printf ? I.e. Are the methods below
legal ?


class X                // An example:
{
 public:
 void printf(...);     // Accepted by BC++ and Visual C++
 void operator()(...); // Accepted by BC++, Visual C++ "crashes" on
this.
};


Thanks,
Morten M. Christensen
Odense Lind=F8, Denmark



[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]