Solved

Convert blank string to reference

Posted on 2004-09-29
2
206 Views
Last Modified: 2010-04-01
I have a function which returns a reference to a string(std::string).  How do I go about returning a reference to a blank string if certain conditions are not met?
0
Comment
Question by:jewee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12181977
I guess you name "reference" to a pointer? That is:

std::string *SomeFunction(arguments here)

You can always return a NULL pointer if function fails, just

(inside function)
return NULL;

(outside function)
std::string *aString=SomeFunction(arguments here)

if (aString!=NULL) {
     // some action here
}
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 12182024
>>How do I go about returning a reference to a blank string if certain conditions are not met?

A reference to a blank string is just the same as a reference to an empty string, e.g.

void GetQueryResults ( string& strQuery, string& strResults) {

    strResults = ""; // blank out string first, so we return an empty result set if nothing found

     // add results to strResults, if any

    // if nothing was would, strResult is set to empty/blank, i.e. strResults.size() == 0
    // and strResults.empty() == true
}
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question