More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Tuesday, 4 August 2009 1:25:21 PM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 523

Is it preferred to pass a string by reference in C++?

For null terminated string char* or char[], it is already a pointer. Passing by reference only means to pass a pointer. All arrays are always passed by reference, never by value.

STL string
1. STL string is NOT a primitive data type; it is a class and thus cannot be handled like the traditional pointer to variable.
2. We can pass strings by reference (string& myString, or const string& myString) or by value (string myString).
3. const string& myString mimics the protection of a variable that passing by value but saves copying overhead. In this case, passing by reference is preferred.


Sponsor
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.