The C++ String Class

Ok I am building a class definition and I am trying to define some private members using the standard library strings

This is my BookData.h header file containing my class definition

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
#include <string>


class BookData
{
	private:
		string	bookISBN;
		string	bookTitle;
		string	bookAuthor;
		string	bookPub;
		string	bookDate;
		int		bookQty;
		double	bookCost;
		double  bookPrice;


	public:
		// Accessors
		string getIsbn()
		{
			return bookISBN;
		}

		string	getTitle()
		{
			return bookTitle;
		}


The header file contains other accessors and mutators for the other private members as well. This give me a LOT of errors when I try to link this in with my project. It is not allowing me to create the string objects for some reason. It is not defining any of my variables of type string and it is not recognizing any of them when I use them afterwards. Basically the string header file is not getting included.

I am using VS2008. Anyone have any idea why this is happening to me?
You need to fully qualify string, because it is defined in the std namespace:

 
std::string bookISBN;


etc etc
Ah, of course, how silly of me. Thank you, thank you.
or
using std::string;
Never use anything at file scope in a header file.
Never use anything at file scope in a header file.

agreed.
but seems op's code is a project with controllable scope and using won't pollute the namespace much, and save a lot of typing.
Last edited on
Is it worth cutting corners?
ask michael shumacher!

you can have the using std::string in the class scope can you not?


edit: no you can't, not for a non-member.
Last edited on
You could temporarily use using namespace std; and then take advantage of the editor/IDE search and replace features to save some typing. You might also find common conflicts this way--which, might be nice to resolve in case a user actually does try to bring everything into global scope.
Topic archived. No new replies allowed.