Re: Operator...
martyn_dobson@hotmail.com wrote:
this has probably been asked/suggested many timtes before, but i just
thought of it.
why is there no such thing as something like operator...()
imho it would allow us to smooth off one of the sharper corners of c+
+.
you could maybe do something like this:
class string
{
public:
const char *operator...() const
{
return c_str();
}
};
void foo(const char *format, ...)
{
//the usual vaarg stuff
}
void bar()
{
string s = "test";
foo("this is a test %s", s);
}
just a quick thought,
Well, on the first glance it looked OK, but then I thought, so why can't
you just do
foo("this is a test %s", s.c_str());
? It would accomplish the exactly same thing without changing the
language. Do you think you could give an example that couldn't be
countered by a use of a static_cast<> or a member function that already
exists?
Generally speaking, you're promoting the lowest rank conversion operator
which can be used when no other standard or user-defined conversion is
suitable, I am guessing. Since I don't use conversions that much I
can't really immediately see where else (aside from the actual '...') it
would be useful.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask