Solved

Convert blank string to reference

Posted on 2004-09-29
2
207 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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

734 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