Returning strings from functions

Hello again everyone,
I hope it doesn't seem like I am spamming the forums (my third topic in as many days) but I really tried searching for this topic, and I found nothing pertaining to my question exactly. There WERE some discussions I found via google that were really far too advanced for me to really grasp...Perhaps given a little time...
Anyways, my question is if there is a simple way to use a string as a class member, and then have a simple accessor method that can return this string. For example what I have here, trying to create a book class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Book{
	public:
	enum Genre{
		fiction=1,nonfiction,periodical,biography,children
	};
	
	//Use a struct to represent ISBN of Book
	//struct ISBN {
	//	int n1; int n2; int n3; char ch;};
	
	//Check for valid Book and initialize, no default constructor
	Book(str title, str author, Genre g, int copyright );
	
	
	///Nonmodifying Operations
	string get_title() const {return title;}
	string get_author() const {return author;}
	int get_copyright() const {return copyright;}	
	bool get_status const {return is_avail;}
	Genre get_genre() const {return g;}
	
	//Modifying Operations
	void check_in() {is_avail = true;}
	void check_out() {is_avail = false;}
	
		
	private:
		
		string title;
		string author;
		Genre g;
		int copyright;
		bool is_avail;
		
}

Book::Book(string tt, string ar, Genre gg, int cpy){
	title = tt;
	author = ar;
        g = gg;
        copyright = cpy;
        is_avail = true;
        //Insert some validity checking here
}

Now, before too many heads explode looking at this, I would just like to say that this is just a description of what I would like to do. I do not assume it works.
The thing is, how would I go about implementing the get methods? Firstly, I am at a stage in the book where pointers haven't even been introduced yet, so apparently I don't need them? From my rudimentary knowledge, I think that in other circumstances, I would pass a pointer to a string. But when the string is an attribute of the object, would I still need a pointer? Or is the problem the return type for the accessors: should I be returning string&? But just changing that doesn't solve the problem.
Perhaps I am going about this completely the wrong way. I know a little about passing strings via pointers, but as I mentioned above, this was "standalone" strings, and when they are in a class, it gets a little too confusing for me.
Again, thanks everyone for all the help!
P.S. I had to comment out that struct for ISBN, because I don't even want to think about the accessor for that, when I can't even get to my strings!!!
would this not work?

1
2
3
4
std::string Book::getAuthor()
{
        return author;
}
I do not assume it works.


Well it does ;P. The only thing you have wrong that I can see is that you used 'str' in some places instead of 'string'. But other than that it looks just fine.

Firstly, I am at a stage in the book where pointers haven't even been introduced yet, so apparently I don't need them?


That's correct. You don't need them here. You can use a string just as you would use an int. Pointers are a completely separate topic and have nothing to do with this particular problem.

should I be returning string&?


No.
Topic archived. No new replies allowed.