Johannes Klauß
Johannes Klauß

Reputation: 11020

Compiling problems with wstring in c++

I need to refactor a .dll for a Zinc based Flash application.

After copy&paste a class from the master to the branch, I'm getting some strange compiling errors:

GameInfo.h(15): error C2146: syntax error : missing ';' before identifier 'm_wsVersion'
GameInfo.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
GameInfo.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

The addressed code:

// removed the comments
#include "stdafx.h"
#include <string.h>

class GameInfo {

public:

    UINT m_uiGameId;

    wstring m_wsVersion; // Line 15

    UINT m_uiCheckSum;

    wstring m_wsFilePath; // Same error report as on line 15

public:
    static BOOL createFromFile(wstring path, GameInfo &target); // error "error C2061: syntax error : identifier 'wstring'" thrown
};

I use Visual Studio 2010 and in the IDE itself everything is okay, no syntactical errors or something like that. And as said I did not touch the code, headers seem fine.

Has anyone a clue what about this error?

Upvotes: 2

Views: 10901

Answers (2)

juanchopanza
juanchopanza

Reputation: 227390

Try using the string header, and qualifying the namespace:

#include <string>

class GameInfo {
   ....  
   std::wstring m_wsVersion;
};

Upvotes: 6

jdehaan
jdehaan

Reputation: 19928

#include <string> is the right standard include in C++ for string classes and use std::wstring.

I strongly recommend AGAINST using a using namespace std; inside one of your headers, as you would force anybody using the header to pull in the std stuff into the global namespace.

Upvotes: 2

Related Questions