473,657 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"named parameters mechanism"

What is named parameter mechanism? Any ideas? I am looking through some
code and there is a comment saying "VC++ has trouble with the named
parameters mechanism", which i have no idea what this means.

Any help much appreciated,

Adam
Jan 23 '06 #1
3 2612
Adam Hartshorne wrote:
What is named parameter mechanism? Any ideas? I am looking through some
code and there is a comment saying "VC++ has trouble with the named
parameters mechanism", which i have no idea what this means.

Any help much appreciated,

Adam


http://www.parashift.com/c++-faq-lit...html#faq-10.18

Regards, Stephan

Jan 23 '06 #2
Adam Hartshorne wrote:
What is named parameter mechanism? Any ideas? I am looking through some
code and there is a comment saying "VC++ has trouble with the named
parameters mechanism", which i have no idea what this means.

Any help much appreciated,


Also called "Named parameter idiom", see this newsgroup FAQ.
(http://www.parashift.com/c++-faq-lit...html#faq-10.18)

HTH

Fabio
Jan 23 '06 #3
"Adam Hartshorne" <ad**@dcs.warwi ck.ac.uk> wrote in message
news:43******** **@mk-nntp-2.news.uk.tisca li.com
What is named parameter mechanism? Any ideas? I am looking through
some code and there is a comment saying "VC++ has trouble with the
named parameters mechanism", which i have no idea what this means.

Any help much appreciated,

Adam


Consider a standard C++ function:

void foo(int x, int * ptr)
{
//stuff
}

If you call the function with

foo(a, b);

then a is treated as an int, and b is treated as a int *, in accordance with
the function declaration, i.e., the order in which arguments are supplied
strictly determines the way in which they are interpreted. The first has to
be an int and the second has to be an int*.

With named parameters, by contrast, there is a syntax available whereby you
can specify the type of the function arguments that you supply, thus giving
freedom in the order in which arguments are entered.

Since C++ does not support named parameters, except with elaborate
workarounds, the comment either refers to such workarounds or to something
completely different. I suspect it might be the latter (in which case the
phrase is being misapplied).

I suspect that the comment actually means is that VC++ 6 doesn't cope well
with the following situation:

#include <iostream>
using namespace std;
struct A
{
A()
{cout << "This is A\n"; }
};
struct B
{
B()
{cout << "This is B\n"; }
};

template <class T>
void foo()
{
T t;
}
int main()
{
foo<A>();
foo<B>();

return 0;
}

Here you will note that the template parameter T is not used as a type in
declaring foo's function parameters, i.e., we don't have, say,

template <class T>
void foo(T t)
{}

Accordingly, template parameters cannot be deduced from the function
arguments supplied. This means you must distinguish different instantiations
of the template by explicitly *naming* the template argument, as in foo<A>()
and foo<B>().

You will note if you run the code on VC++ 6 that it gets it wrong and the
output is

"This is B";

both times.

The workaround is to always use template parameters in the list of function
parameter types, supplying dummy arguments as necessary when calling the
function, e.g.,

template <class T>
void foo(T * ptr)
{
T t;
}

int main()
{
foo((A*)0);
foo((B*)0);

return 0;
}

--
John Carson

Jan 23 '06 #4

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

Similar topics

4
3957
by: Marc Elser | last post by:
Hi Everybody, Can someone please tell me how to access the form name if there's a form field named "name", for example: <form name="myform"> <input type="text" name="name" value="Marc"> <input type="button" onClick="alert(this.form.name);"> </form>
11
2453
by: Florian Loitsch | last post by:
I'm currently writing a JS->Scheme compiler (which, using Bigloo, automatically yields a JS->C, JS->JVM, JS->.NET compiler), and have a question concerning the function-parameters: According to the spec (10.1.6) the activation-object already contains the the parameters-object when the variables are instantiated (10.1.3). The question is now: does a parameter "parameters" overwrite the "parameters"-object or not? All three implementations...
3
8823
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I don't think I made any changes to either page other than changing the user control that creates the header). Server Error in '/myApp' Application. ---------------------------------------------------------------------------- ----
4
4398
by: Ying Lu | last post by:
Hello, I have a table named "USER" under MySQL database. When I am trying to move tables from MySQL to PostgreSQL, I found that I could not create a table namely "USER". I guess "USER" is a key string used by PostgreSQL system so that we could not create a table named "USER". Is that true? Thanks a lot, Emi Lu
5
4519
by: funkyj | last post by:
I love pexpect because it means I may never have to use expect again (I don't do any heavy expect lifting -- I just need simple tty control)! As a python advocate I find it embarassing how difficult it is do the following in python (without pexpect): - logon to a remote system using ssh - do an 'ls' and exit the remote shell - print the output from the remote shell session.
1
3773
by: ye juan | last post by:
Hi, all I have some questions to ask: 1. How can I add a standard module named "datetime" in Jython when the error happens :"Traceback (innermost last): File "C:\python\test.py", line 3, in ? ImportError: no module named datetime " The line 3 is writen: "from datetime import datetime,
4
2033
by: Gary Brown | last post by:
Hi, Why are fn(object parameters) and fn(params object parameters)
6
9201
by: alexia.bee | last post by:
Hi all, I need to write app in C# that communicates with other app. I need to use "named event" for that. I should use windows APIs SetEvent() and WaitForSingleObject() etc... I looked for help but couldn't find any. Can any one please help me with that? Thanks.
2
27711
by: whitsey | last post by:
Trying to concatenate two fields into one however I seem unable to do so. All I want is to execute the following SELECT MONTH(L.DATE) ||' '|| YEAR(L.DATE) as MTH_OF_YEAR FROM LOG L But I get this error:
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.