c++ - C2146 失踪;在 Visual Studio 2010 中

标签 c++ visual-studio

当我尝试在 VS 2010 中编译时出现以下错误。它还提示字符串未定义,这是没有意义的,因为我清楚地包含了它。我明白这些错误的含义,但它们似乎没有任何意义:

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'

这是我的代码:

#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

}
};

在我扯掉头发之前,我们将不胜感激!

谢谢!

最佳答案

string 是 std 命名空间的一部分,因此您必须将其称为 std::string。这同样适用于 map 。

关于c++ - C2146 失踪;在 Visual Studio 2010 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4179180/

相关文章:

c++ - 使用 C++ builder 读取 gmail pop3

android - Visual Studio 如何在 Android/Xamarin 调试运行期间禁用 VS 输出窗口的自动滚动到底部?

javascript - EsLint 与 2017 相比不起作用

c# - 在 VS 测试项目中维护单元测试方法之间的上下文

c - 当实际上永远不会发生溢出时,Visual Studio 会发出缓冲区溢出警告

c++ - std::array::max_size 和 std::array::size 给出不同结果的示例

C++11,仅将一个字段复制到 vector 中

c++ - 为什么 Qt 拒绝有效的 JSON?

c++ - C++ 享元模式

html - <br> 而不是 Visual Studio 中的 <br/>