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 guy2y ago
the function is expecting a reference of the string to be returned I think string&
Revan
RevanOP2y 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 guy2y 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
RevanOP2y 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 guy2y 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
RevanOP2y ago
Revan
RevanOP2y ago
im getting this error
the magic guy
the magic guy2y 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
RevanOP2y ago
oh i see lol thank you it works now
Want results from more Discord servers?
Add your server