cgarza
11-01-2011, 02:56 AM
Having a problem with classes and strings and pointers.
class Person
{
protected:
string fname;
public:
string* get_fname();
void set_fname();
friend std::istream& operator >> (std::istream&, Person&);
friend std::ostream& operator<<(std::ostream&, Person&);
};
string* Person::get_fname()
{
return(fname);
}
int main()
{
Student S1 = new Student;
S1 -> set_fname();
S1 ->get_fname();
return(0);
}
I compile and I get the error
cannot convert "Person::fname' from type 'string' to type 'string *'
Can someone explain what i am doing wrong?
Thank You
class Person
{
protected:
string fname;
public:
string* get_fname();
void set_fname();
friend std::istream& operator >> (std::istream&, Person&);
friend std::ostream& operator<<(std::ostream&, Person&);
};
string* Person::get_fname()
{
return(fname);
}
int main()
{
Student S1 = new Student;
S1 -> set_fname();
S1 ->get_fname();
return(0);
}
I compile and I get the error
cannot convert "Person::fname' from type 'string' to type 'string *'
Can someone explain what i am doing wrong?
Thank You