CAN YOU HAVE A MEMBER FUNCTION RETURNING A STRING IN A CLASS

Hi everyone, Is it possible to have a member function return a string in a class. for example:

1
2
3
4
5
6
7
class myClass{
public:
[...]
string returnStr();
private:
int blar_blar;
}
Yes. Not just a string. It can return any kind of object that you can define.
I have a counter question: Is there anythin you CAN'T have a member function return???
I'm getting the error "string does not name a type" but when i comment the member function out. my program runs perfectly fine. Do you guys have any idea what this error means and what could be causing it?
Do you include string header file in header part of the file where you declare and implement your class, myClass?
#include <string> is included both in the header file and the implementation file.
And did you remember to specify the namespace?
Try the following

std::string returnStr();
@viliml

static arrays?
@ToniAz: Can ANY function return an array? Any kind of array? No, just pointers! I meant, is there something you CAN return from a global function, but mnot from a member function!
Last edited on
Topic archived. No new replies allowed.