简单代码需要帮助 - 没有构造函数实例匹配参数列表

use*_*284 5 c++ intellisense vector

我正在关注一本关于 C++ 编程的书,但我陷入了向量的困境。书中的例子是:

vector<int> v = {1,2,3};
Run Code Online (Sandbox Code Playgroud)

但我收到一个错误:

    1   IntelliSense: no instance of constructor "Vector<T>::Vector [with T=int]" matches the argument list
        argument types are: (int, int, int) ../path
Run Code Online (Sandbox Code Playgroud)

另外,当我创建字符串向量时:

vector<string> v = {"one", "two", "three"}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

    1   IntelliSense: no instance of constructor "Vector<T>::Vector [with T=std::string]" matches the argument list
        argument types are: (const char [4], const char [4], const char [6]) ../path
Run Code Online (Sandbox Code Playgroud)

我正在使用 VS 2013 和 2013 年 11 月的 CTP 编译器。我究竟做错了什么?

T.C*_*.C. 5

总结并扩展评论和 Bjarne Stroustrup"std_lib_facilities.h"标题中所写的内容:

  • 标头包含一个简单的范围检查向量类,用于Vector教学目的;
  • 为了在标准库中进行Vector“无缝”替换vector(同样,出于教学目的),标头包含以下行:

    // disgusting macro hack to get a range checked vector:
    #define vector Vector
    
    Run Code Online (Sandbox Code Playgroud)
  • OP 可能使用了本书第一版的标题(它是 的 Google 搜索结果的顶部std_lib_facilities.h),它Vector没有initializer_list构造函数(该版本使用 C++98,它没有初始化列表)。
  • 结果,编译器Vector在看到 时抱怨没有匹配的构造函数,这在宏替换后vector<int> v = {1,2,3};变为。Vector<int> v = {1,2,3};

要解决此问题,请下载并使用正确版本的标头。