473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

type wildcards (or something similar) for function parameters

Hi,

is there any way to define a function where one or more parameters might
be of any type, since they aren't used in the function?

In particular, I'd need an operator <<() which always throws an error
and doesn't care which type its second argument is, so ideally I'd like
it to be like:

Stream &operator(Stream &s, anytype-here)
{
throw Blobb;
}

Naively, I have tried

Stream &operator(Stream &s, ...)

which doesn't work.

In general, I'd like to be able to define a function f with one or more
parameters which remain of unspecified type, like I could do, for
example, in SML:

fun f x y = 1+x;
val 'a f = fn : int -'a -int
(here the type of the second argument, y, is not specialized and is
represented by the type variable 'a).

Is this possible to achieve in C++?
Aug 22 '08 #1
4 1478
I wrote:
is there any way to define a function where one or more parameters might
be of any type, since they aren't used in the function?
Ah, just ignore it, in this particular case it can be done by simple
function templates (...).
Aug 22 '08 #2
On 2008-08-22 09:14:30 -0400, Matthias Buelow <mk*@incubus.desaid:
Hi,

is there any way to define a function where one or more parameters might
be of any type, since they aren't used in the function?

In particular, I'd need an operator <<() which always throws an error
and doesn't care which type its second argument is, so ideally I'd like
it to be like:

Stream &operator(Stream &s, anytype-here)
{
throw Blobb;
}

Naively, I have tried

Stream &operator(Stream &s, ...)

which doesn't work.
Apparently "doesn't work" means doesn't satisfy some requirement that
hasn't been mentioned, since the code snippet above seems to do exactly
what was requested. In what way does this not work?

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Aug 22 '08 #3
On Aug 22, 3:33*pm, Matthias Buelow <m...@incubus.dewrote:
Pete Becker wrote:
Apparently "doesn't work" means doesn't satisfy some requirement that
hasn't been mentioned, since the code snippet above seems to do exactly
what was requested. In what way does this not work?

Consider got the following example:
[snipped example showing that operator<< must have exactly two parms]

In addition, you can't pass non pod types via '...', so the solution
also fails the requirement that the unused parameter can be of any
type.

--
gpd
Aug 22 '08 #4
gpderetta wrote:
In addition, you can't pass non pod types via '...', so the solution
also fails the requirement that the unused parameter can be of any
type.
Well, I'd think it could figure out that in this case, the second one
isn't used and hence not needed and also omit the type circus from that
argument but that's probably asking too much.

Aug 22 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Lenard Lindstrom | last post by:
I was wondering if anyone has suggested having Python determine a method's kind from its first parameter. 'self' is a de facto reserved word; 'cls' is a good indicator of a class method ( __new__...
1
by: John Miles | last post by:
Hi -- This is a bit of an implementation-specific problem, but I'd like to post it here to see if there's a general answer within the auspices of the language. I'm developing a high(er)-level...
27
by: Marlene Stebbins | last post by:
I am experimenting with function pointers. Unfortunately, my C book has nothing on function pointers as function parameters. I want to pass a pointer to ff() to f() with the result that f() prints...
12
by: confusedcoder | last post by:
Suppose I have the following function: void doSomething(char** array, int size); Normally, I would call the function with an array of, say, 3 elements... char* strs = { "str1","str2","str3"...
5
by: Andreas Müller | last post by:
Hi, I was wondering, if there is something similar in VB.NET like the using statement in C#. What it does is to automatically call Dispose on the object decrared with in the statement when the...
3
by: Iker Arizmendi | last post by:
How are function parameters of rowtype specified when calling them from a client such as libpq? Is there a syntax similar to that for arrays? (eg, {x, y, z} ) Thanks, Iker ...
21
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if...
7
by: lovecreatesbea... | last post by:
Shoud we declare non-pointer function parameters with const keywords? int main(void){ int f(const int i); int i; f(i); return 0; }
3
by: =?ISO-8859-15?Q?Jean=2DFran=E7ois?= Lemaire | last post by:
Hello, I'm having a discussion with someone who sustains that function parameters, when they are smaller than an int (say short or char) are automatically promoted to int before being passed to...
5
by: nidaar | last post by:
From a security point of view, is accepting wildcards like "%" in input parameters of stored procedures against any best practices? As an example, if a user defined function uses "Productname...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.