-1
#ifndef vid
#define vid
#include<cstring>
#include<string>
#include<string.h>


class Video
{
protected:
 string title;
 int id;
 string genre;
 string type;
 string actor;
 bool available;


public :
 virtual double rent();
 virtual void displayDetails();

};


#endif

I get this error on declaration of all string attributes.

error C2501: 'string' : missing storage-class or type specifiers Please help

billz
  • 44,644
  • 9
  • 83
  • 100
Sohaib Jamal
  • 109
  • 12
  • Why are you including every possible string header? The only one you need in this case is `string` – Praetorian Sep 07 '13 at 13:40
  • @Praetorian: he was probably experimenting to get the string recognized properly, and left it in there before posting. I would not make a fuss about it. – László Papp Sep 07 '13 at 13:49
  • 1
    @LaszloPapp Umm, `string.h` and `cstring` are inherited from the C standard library and will never fix any problems with `std::string`. And how is pointing out something dubious to a beginner *fussing*? If anyone's being fussy, it's you whining about the *merits* of mentioning adding `using namespace std;` *in a header* to a beginner. – Praetorian Sep 07 '13 at 13:57
  • I do not understand your post. When someone is a beginner, that person will try everything to solve the issues, including header files. You are not pointing at anything new btw because I already did that in my reply, and yes typing "std" many times when _unneeded_ is uncomfortable. – László Papp Sep 07 '13 at 14:01

2 Answers2

3

string is defined under std name space, you could fix your code by providing full namespace:

std::string genre;
std::string type;
std::string actor;
billz
  • 44,644
  • 9
  • 83
  • 100
  • I think this is a bad suggestion without providing alternatives with pro/cons. If there is no namespace clash, I do not think anyone would like to type this much. – László Papp Sep 07 '13 at 13:48
0

string is included in namespace std.

So either qualify the identifier directly as:

std::string

Or use using directive(which should not be preferred for such limited use)

using namespace std;
string str;

Or use a using declaration

using std::string;
string str;
Saksham
  • 9,037
  • 7
  • 45
  • 73
  • I don't think the second option is a good idea. Newcomers should not be encouraged to use that. Bear in mind that this is a header file. – juanchopanza Sep 07 '13 at 13:16
  • @juanchopanza if you read properly, I have already written that. Is that the downvote for? – Saksham Sep 07 '13 at 13:20
  • Yeah, the file in question is a header, so even mentioning `using namespace std` is a bad idea. OP might decide to go with that and break their or someone else's code. – juanchopanza Sep 07 '13 at 13:23
  • Saksham: fwiw, I disagree with juan. I think it is good to mention all the possibilities with its pro/cons, and that is I personally did after his comment for my reply. – László Papp Sep 07 '13 at 13:29
  • @LaszloPapp yes. Thanks!. seems juan is on a spree of downvoting every answer. – Saksham Sep 07 '13 at 13:32
  • Saksham: that is fine as he is entitled to. What I dislike personally is that when someone applies his suggestion, he keeps the downvoting there. That is not fair. – László Papp Sep 07 '13 at 13:34