More Group Sites
School Rankings
Jobless Net
Better Home
Enviro++


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest Search | Active Topics | Members | Log In | Register

Is it preferred to pass a string by reference in C++? Options · View
hong
Posted: Tuesday, August 04, 2009 5:25:21 PM

Rank: Administration
Groups: Administration

Joined: 11/23/2008
Posts: 335
Points: 711
Location: Australia
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
Posted: Tuesday, August 04, 2009 5:25:21 PM
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.

Main Forum RSS : RSS

ASPNET Theme created by Boskone (Dan Ferguson)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.
This page was generated in 0.213 seconds.