General discussion

Locked

C++ Forum (Continued)

By discussion ·
Welcome to the C++ Forum. This is the place to post your C++ questions, share your best techniques, and express your opinion on topics that impact IT development. We also encourage you to post your comments about the C++ TechMail.

If you haven't subscribed to the C++ TechMail, visit our e-newsletter subscription center to subscribe to this free e-newsletter:
http://nl.com.com/guest.jsp?brand=builder&return_to=http://builder.com.com:8001/2001-1-0.html

Also, don't miss the discussion from the previous C++ Forums. Use the links below to catch up on earlier member comments.

- http://builder.com.com/5208-6230-0.html?forumID=18&threadID=119003

- http://builder.com.com/5208-6230-0.html?forumID=18&threadID=123032

Note: When pasting links into your browser, remember to first remove any spaces.

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Feedback about default argument values tip

by MaryWeilage Editor In reply to C++ Forum (Continued)

Note from the editor: The following comments are from member Walter Tross about the Feb. 25th edition of the C++ e-newsletter entitled, "Default argument values in pointers to functions and typedefs."

Your article about default arguments is fine. Just one thing: you forgot to tell us WHAT the standard says. If I remember well, it says something like default arguments can appear only in one place for the same function in the same compilation unit - but I could be wrong.
The idea of talking about proprietary extensions to the standard which can make your code nonportable is good, I would like to read more about this. I for myself, e.g., always painstakingly re-enable for loop scope conformity every time I start a new project in Visual C++ (/Zc:forScope). I hate the fact that Microsoft lets you write this code by default:

for (int i=0; i<n; i++) if (a) break; if (i<n) ...

(FYI: There's supposed to be an i with brackets around it after the a in this code, but the brackets aren't appearing in this discussion.)

And you can't even disable language extensions altogether (/Za), because many Microsoft header files won't compile.
But also the GNU compiler has extensions, like typeof, which is very useful in macros. I have seen it in a list of possible language improvements written by Stroustrup. But ok, I don't want to write an article myself :-)

Cheers,
Walter Tross

Collapse -

default arguments

by dannyk In reply to Feedback about default ar ...

The issue of standard extensions is very wide and I intend to cover some of the most common features in future tips.
As for default argument, the Standard says quite a lot (in fact, too much, IMHO).

A default value may appear in a function declaration or definition. It is possible to have multiple declarations with different default values so long as the overriding declaration appears in an enclosed namespace of an outer namesapce. In other words, you can have something like this:

void f(int x, int y=0); //#1
<code>
int func()
{
void f(int x, int y=8); //#2, fine, overrides #1
void f(int x, int y=9); //#3, illegal

f(8); //f(8,8); becaue of #2
}
</code>

That said, such programming style is disatrous. My advice is to define default values only once, in a function's prototype.

Placing default values in a typedef, pointer to function or pointer to member isn't allowed according to the Standard.

Danny Kalev

Collapse -

Sorry to say it, you're hoist on your won petard

by tre In reply to default arguments

A default value may appear in a function declaration or definition. It is possible to have multiple declarations with different default values so long as the overriding declaration appears in an enclosed namespace of an outer namesapce. In other words, you can have something like this:

void f(int x, int y=0); //#1
<code>
int func()
{
void f(int x, int y=8); //#2, fine, overrides #1
// redfinition of function f - in the same NAMESPACE
void f(int x, int y=9); //#3, illegal

f(8); //f(8,8); becaue of #2
}

Collapse -

Dyslexic fingers

by tre In reply to Sorry to say it, you're h ...

Should be: OWN petard

Collapse -

C++ Question

by kellykey In reply to C++ Forum (Continued)

What is the C++ equivilent to a Class.forName command in Java?

Collapse -

good question...

by dannyk In reply to C++ Question

Standard C++ doesn't have an equivalent function. Dynamic loading in general isn't standardized in C++ so each implementation defines its own APIs and libraries for dynamic loading. If you're interested in reflection per se, there's a quasi-standard reflection on www.boost.org that offers a similar mechanism.

Danny

Collapse -

ForName

by tre In reply to good question...

forName returns the Class object associated with the class or interface with the given string name, using the given class loader.

This is equivalent to the macro 'RUNTIME_CLASS' in MFC - I presume there is an equivalent macro/funtion/statement for UNIX/LINUX implementions of windowing objects for C/C++.

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums