简体   繁体   中英

C2146 Missing ; in Visual Studio 2010

I am getting the following the following errors when I try to compile in VS 2010. It is also complaining that string is undefined, which makes no sense, as I clearly included it. I understand what the errors mean, but they don't seem to make any sense:

1>c:\\users\\jon\\documents\\visual studio 2010\\projects\\project 2\\project 2\\userfactory.cpp(11): error C2146: syntax error : missing ';' before identifier 'profession' 1>c:\\users\\jon\\documents\\visual studio 2010\\projects\\project 2\\project 2\\userfactory.cpp(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\\users\\jon\\documents\\visual studio 2010\\projects\\project 2\\project 2\\userfactory.cpp(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\\users\\jon\\documents\\visual studio 2010\\projects\\project 2\\project 2\\userfactory.cpp(16): error C2143: syntax error : missing ';' before '<' 1>c:\\users\\jon\\documents\\visual studio 2010\\projects\\project 2\\project 2\\userfactory.cpp(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\\users\\jon\\documents\\visual studio 2010\\projects\\project 2\\project 2\\userfactory.cpp(16): error C2238: unexpected token(s) preceding ';' 1>c:\\users\\jon\\documents\\visual studio 2010\\projects\\project 2\\project 2\\userfactory.cpp(23): error C2061: syntax error : identifier 'string' 1>c:\\users\\jon\\documents\\visual studio 2010\\projects\\project 2\\project 2\\userfactory.cpp(19): error C2061: syntax error : identifier 'map'

This is my code:

#include "objbase.h" //I found this recommendation while googling, but had the errors prior to adding this.
#include <string>
#include <map>
#include <utility>

class UserFactory {
public:
    class User {
        char gender;
        int id;
    string profession;// line 11
    int zip;
    friend class UserFactory;
};
private:
map<int,User*>* map;

public:
UserFactory() : map(new map<int,User*>()) { }

virtual ~UserFactory(void);

void process(string s) {
    //user id | age | gender | occupation | zip code

}
};

Any help would be appreciated before I rip my hair out!

Thanks!

string is part of the std namespace, so you must refer to it as std::string. The same applies to map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM