0

I'm having an issue with strings in a header file in my XCode 5.0.2 project. I'm very new to C++ and trying to understand what is going on. Here is my code:

#include <string>

#ifndef Blah__H
#define Blah__H


class Blah {
    char kind;
    std::string str;
    Blah(char ch) : kind(ch), str("") { }
    Blah(char ch, std::string s) : kind(ch), str(s) { }
};
#endif /* defined(Blah__H) */

The error Xcode is giving me says "No type named 'String' in namespace 'std'; did you mean 'string'?"

I've tried removing the std:: and as I expected, it complained that it needed them. What am I doing wrong? I cannot figure out why it is looking for a type 'String' (capital S), whereas my code says 'string'.

Thanks in advance for your help!

  • You're using a [reserved identifier](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier). – chris Feb 22 '14 at 20:32
  • 2
    Are you sure you don't have `String` on some other line in some other file? – Joseph Mansfield Feb 22 '14 at 20:32
  • @JosephMansfield That was it. Like I said, I'm new to this. I'm in a C++ class and we were given a standard header to include in our code. I searched through it and found String defined as a struct. Thanks for your help! – cory.thompson527 Feb 22 '14 at 20:39
  • The error which you get is in the header or at place where you call this class? Also the class you have provided in example has everything as private. – Nik Feb 22 '14 at 21:01
  • @Nik The compiler pointed to the error in the header. It pointed to both strings. Joseph answered the problem, 'String' was defined somewhere else in the program. – cory.thompson527 Feb 22 '14 at 21:07
  • @Nik And yeah, the example was private. I messed that up. It is actually a struct that the actual class uses. – cory.thompson527 Feb 22 '14 at 21:09

0 Answers0