Why can't I just return the string in my query function?

I'm not sure why I can just return the string in this query function
9 Replies
the magic guy
the magic guy16mo ago
the function is expecting a reference of the string to be returned I think string&
Revan
Revan16mo ago
do i make declare title to be string& in my class declaration? or do i do it in my function?
the magic guy
the magic guy16mo ago
I think you want it to return a copy of the string just string change it in both your function prototype and declaration
Revan
Revan16mo ago
the function prototype and declaration was given to me, i can't change that so i guess do i make a temp variable and return that? i can only change the member variables or add more variables
the magic guy
the magic guy16mo ago
wait a sec its been too long idk c++ lmao this should work
class Person
{
private:
string m_name;

public:
const string& getName() const { return m_name; }
};
class Person
{
private:
string m_name;

public:
const string& getName() const { return m_name; }
};
Revan
Revan16mo ago
Revan
Revan16mo ago
im getting this error
the magic guy
the magic guy16mo ago
your prototype and func implementation doesnt match up oh wait change the name of your function to not be the name of your class member getTitle()
Revan
Revan16mo ago
oh i see lol thank you it works now