PDA

View Full Version : Methods returning stl strings



dharrison
01-30-2008, 02:19 PM
Maybe I am missing something obvious. Here is a short example:



#include <iostream>
#include <string>

using namespace std;

class sample {
public:
sample(const string& val) : m_val(val) { };
string val() { return m_val; };
protected:
string m_val;
};

int main(int argc, char** argv)
{
string val("foo");
sample* s = new sample(val);
/* set breakpoint here */
cout << s->val() << endl;
return 0;
}


If I set a break point where I have indicated above and
then use the evaluate panel to try to evaluate:

s->val()

I get the error:



calling functions which return an aggregate by value is not supported


If I have a function that returns an STL string, how can
I call it? Note: this example is purposefully simple. In the
real app, the string is computed (not stored).