🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #852

Re: Passing constants through reference types

#852
From: Rusty, Paul , Russell
Date: Tue, 05 Dec 1995 06:52
27 lines
1462 bytes
In message <49vmsa$ju0@mark.ucdavis.edu> you write:
> I'm using the libg++ String type a lot, and I want to pass it through
> arguments as a reference.  Otherwise, the program has to make a
> complete copy of the thing onto the stack.
> 
> However, sometimes I want to do something like:
> 
> void foo(String &);
> 
> foo("hello");

Hi Dan,
	I think your problem is that you are using "String &" not
"const String &".  "String &" implies that you might change the parameter
being passed.  Since in this case, the parameter is a temporary instance
of String, this is unlikely to be what you want.

	Try "foo(const String &)" and it should be fine.

	Of course, you may need to get cast away the const inside
foo() in order to call SubString operations...

Hope that helps,
Rusty.
--
Rusty.Russell@adelaide.maptek.com.au           "Engineer? So you drive trains?"
Lies, damned lies, and out-of-date documentation.        #include <stddisclm.h>
Technical Details
Message-ID: <199512050650.RAA13317@gauss.adelaide.maptek.com.au>
Path: arc1-ca.pugleaf.net!adelaide.maptek.com.au!Rusty.Russell
References: <49vmsa$ju0@mark.ucdavis.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!adelaide.maptek.com.au!Rusty.Russell
From: Rusty.Russell@adelaide.maptek.com.au (Rusty, Paul ,  Russell)
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: Re: Passing constants through reference types
Date: 5 Dec 1995 01:52:14 -0500
Organization: Gatewayed from the GNU Project mailing list help-g++@prep.ai.mit.edu
Sender: daemon@cis.ohio-state.edu
Distribution: world
Message-ID: <199512050650.RAA13317@gauss.adelaide.maptek.com.au>
References: <49vmsa$ju0@mark.ucdavis.edu>