Solved

Convert blank string to reference

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now