Hey everyone,

I'm trying to create a string inside a class, but for some reason, my compiler is not recognizing:

class ob {
    string name("Name");
public:
      //code
}

error C2059: syntax error : 'string'

This class is being written in a header file, which has #include <string>.

Now, when I use the same code in my main() file, it works fine.

Initialization of class members (except static integral types):

class Ob // avoid all small letters names
{
public: // declare public then protected then private
  Ob():name("Name") {} // member initializators list
  ...
private:
  std::string name; // initialize in constructor(s)!
};

Initialization of class members (except static integral types):

class Ob // avoid all small letters names
{
public: // declare public then protected then private
  Ob():name("Name") {} // member initializators list
  ...
private:
  std::string name; // initialize in constructor(s)!
};

Got it to work, it makes sense. Thank you.

This question has already been answered. Start a new discussion instead.