Discussion Locked

C++ Forum (Continued)

0 helpful
16 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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'tsubscribed to the C++ TechMail, visit our e-newsletter subscription center to subscribe to this free e-newsletter:
http://builder.com.com/techmails.jhtml?repID=u001

Also, don't miss the discussion from the previous C++ Forum. Use the link belowto catch up on earlier member comments. (Note: Due to a technical glitch, you'll need to delete the space after jhtml?.)
http://builder.com.com/forumdiscuss/thread_detail.jhtml?thread_id=119003

16 replies

by Mark W. Kaelin

When to use holding pointers instead of references as class members:

The April 16, C++ TechMail discusses how to use holding pointers instead of references as class members. The tip suggests you should prefer pointers instead of references when you?re developing non-functor classes. Do you agree? Share your expertise with your peers.

If you haven't subscribed to the C++ TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription centerto subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by Mark W. Kaelin

Put functions and data into a Private namespace:

The April 23, C++ TechMail discusses the Private namespace. Have you used the Private namespace to enforce implementation hiding? Tell us how it worked for you.

If you haven't subscribed to the C++ TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by Mark W. Kaelin

Validate input easily with std::string:

The April 30, C++ TechMail discusses validating user input. This tip suggests that to avoid the trouble of manually testing the state of cin after each input operation, you should bypass the validation mechanism of cin altogether and read the input as a string. Do you agree? Tell us why or why not.

If you haven't subscribed to the C++ TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by john torjo

You say:

You'd be surprised that this program compiles:

#include
int main()
{
Days day = Mon;
for (int n=0; n<7; ++n) /* display days as int's */
{
std::cout << day << std::endl;
++day;
}
}

Indeed I would, since it will fail to compile under a Standard compliant compiler.
Indeed, it will fail to compile for VC6, gcc3.2, Comeau (and probably others as well).

There is no default operator ++ for enums.
(unless you define it)

Best,
John

by miles.felton

Yes, but I don't think it's as cryptic as the exclusive-Or version which would be:-
template void swap(T& i, T& j)
{
i = i ^ j;
j = i ^ j;
i = i ^ j;
}
Cute or what?

by Mark W. Kaelin

Construct an object on previously allocated memory:

The May 14, C++ TechMail discusses allocating objects with placement new operator. It is suggested that using placement new instead of ordinary new can be useful in time-critical applications. Have you used the placement new operator? Tell us about your experience. Do you think the placement new operator is useful for your applications?

If you haven't subscribed to the C++ TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by Mark W. Kaelin

Understand the three name linkage types:

The May 21, C++ TechMail discusses the three name linkage types: external linkage, internal linkage, or no linkage. Tell us how you have used the various linkages to establish a name's visibility with other scopes and translation units in your applications. Do you have a better way to accomplish this task?

If you haven't subscribed to the C++ TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by Mark W. Kaelin

Know the definition of NULL in a strongly-typed environment:

The May 28, C++ TechMail discusses the differences between the definition of NULL in C versus C++. Do you prefer the strongly-typed pointers of C++? How has this enhancement helped you in your application development?

If you haven't subscribed to the C++ TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by Mark W. Kaelin

Replace operands' order in a comparison expression to avoid human errors:

The June 2, C++ TechMail discusses a technique to reduce human errors when coding comparison expressions by modifying the order of the operands. Have you used this coding technique? Do you have a better solution? Share it with us.

If you haven't subscribed to the C++ TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by Mark W. Kaelin

Delve into comma-separated expressions:

The June 4, C++ TechMail examines comma-separated expressions. Have you used a comma-separated expression to determine the correct program flow and to predict the side effects that will be applied to the subexpressions?

If you haven't subscribed to the C++ TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by Mark W. Kaelin

Initialize object data with a member list:

The June 9, C++ TechMail examines how to initialize object data with a member list. The tip suggests this method increases efficiency, do you agree? Tell us why or why not.

If you haven't subscribed to the C++ TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by jyotsna_sonawane

Hi !!

I dont work in C++ but its the language I am in love with. I read this article and got some doubts.

In the article, it is said that when we initialize members in constructor, then the parameters are passed by value. Does it mean that when member initialization lists are used then parameters are passed by reference ??

Second, is it allowed to write constructor body if we have specified member initialization list ?

and third, this one is based on asnwers of the above two questions. If answers of above questions is 'yes', then we will be able to modify the passed parameter in the constructor. How correct is it semantically ???

Regards
Jyotsna

by jyotsna_sonawane

Hi !!

I dont work in C++ but its the language I am in love with. I read this article and got some doubts.

In the article, it is said that when we initialize members in constructor, then the parameters are passed by value. Does it mean that when member initialization lists are used then parameters are passed by reference ??

Second, is it allowed to write constructor body if we have specified member initialization list ?

and third, this one is based on asnwers of the above two questions. If answers of above questions is 'yes', then we will be able to modify the passed parameter in the constructor. How correct is it semantically ???

Regards
Jyotsna

by spi

Note: I'm not the author of the article!
1) No, parameters are not "passed by ref.", but since, by using the initialization list, temporary variable are not needed, compiler can avoid them: it's just a kind of optimization.
2) You have at least towrite an empty body {}
3) See 1.

This discussion is closed to new replies.