相关疑难解决方法(0)

Visual Studio 2012中的C++ 11功能

Visual Studio 2012的预览版(VS2010之后的下一个版本)现已推出.

有谁知道它支持哪些新的C++ 11功能?(我现在无法试一试).

c++ visual-c++ c++11 visual-c++-2012

94
推荐指数
4
解决办法
6万
查看次数

初始化一个字符串向量,我已经知道用C++填充它的所有值

在我找到你们的帮助之前,我花了一个多小时研究这个.我正在使用visual studio 2012,我刚刚安装了更新2.

我有这个构造函数

Lexer::Lexer(istream &source1, ostream& listing1)
:source(source1), listing(listing1)
{
vector<string> tempVec = { 
    "and", "begin", "boolean", "break", "call", "end", "else", "false", "halt",
        "if", "input", "integer", "is", "loop", "not", "null", "newline", "or", "output", "procedure"
        "return", "then", "true", "var"
};




tokenToStringVector = tempVec;

for (int k= 0; k < tokenToStringVector.size(); k++)
{
    string key = tokenToStringVector[k];
    lexemeToTokenMap[key] = Token(k); // Function-style type cast
}
}
Run Code Online (Sandbox Code Playgroud)

我的教授写了标题,我写了代码.我收到这个错误,我无法弄清楚:

1>c:\users\sam\dropbox\compiler project\lexical analyzer\lexer.cpp(8): error C2552: 'tempVec' : non-aggregates cannot be initialized with initializer list …
Run Code Online (Sandbox Code Playgroud)

c++ vector

5
推荐指数
1
解决办法
2460
查看次数

在VS2012中不允许使用{...}进行vector <string>初始化?

我想知道如何初始化一个std::vector字符串,而不必push_backVisual Studio Ultimate 2012中使用一堆.


我试过了vector<string> test = {"hello", "world"},但这给了我以下错误:

Error: initialization with '{...}' is not allowed for an object of type "std::vector<std::string, std::allocator<std::string>>


  • 为什么我收到错误?
  • 关于我可以做什么来存储字符串的任何想法?

c++ string vector

3
推荐指数
1
解决办法
2395
查看次数

错误C2797:列出成员初始化列表中的初始化

我正在观看MVA关于C++的教程,我在下面提到的代码是由凯特写的而不是我.然而,她似乎没有编译显示任何错误,但在我的情况下,我得到以下错误:

错误1错误C2797:'NamedRectangle :: _ name':成员初始化列表中的列表初始化或非静态数据成员初始化程序未实现c:\ users\abhimanyuaryan\documents\visual studio 2013\projects\kate demos\17 inheritance\inheritance \namedrectangle.h 12 1继承

代码中的第12行来自我的NameRectangle类继承自Rectangle类:

class NamedRectangle :  public Rectangle
{
public:
    NamedRectangle() { }

    NamedRectangle(std::string initial_name, int initial_width, int initial_height)
        : Rectangle{ initial_width, initial_height }, _name{ initial_name } //--> This line
    {}  

std::string get_name() const { return _name; }

private:
    std::string _name;

};
Run Code Online (Sandbox Code Playgroud)

当我std::string从构造函数中删除initial_name以及_name{initial_name}代码编译时.请解释我,不要把我当作经验丰富的高级程序员.我昨天才开始使用C++.

c++ inheritance visual-studio visual-studio-2013

3
推荐指数
2
解决办法
6010
查看次数