简单代码需要帮助 - 没有构造函数的实例匹配参数列表 [英] Simple Code Need Help - no instance of constructor matches argument list
问题描述
我跟着一本关于C ++编程的书,我被卡住了。这本书的例子是:
I am following a book on C++ programming and I got stuck on vectors. The example from the book goes:
vector<int> v = {1,2,3};
但我收到错误:
1 IntelliSense: no instance of constructor "Vector<T>::Vector [with T=int]" matches the argument list
argument types are: (int, int, int) ../path
此外,当我创建字符串向量:
Also, when I create string vector:
vector<string> v = {"one", "two", "three"}
/ p>
I get this error:
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
我使用VS 2013和2013年11月的CTP编译器。
I am using VS 2013 with Nov 2013 CTP compiler. What am I doing wrong?
推荐答案
总结并扩展评论中写的内容和Bjarne Stroustrup的 std_lib_facilities.h
标题:
To summarize and expand upon what was written in the comments and Bjarne Stroustrup's "std_lib_facilities.h"
header:
- 为了教学目的,标题包含一个小写范围检查的向量类
Vector
/ li>
-
使
向量
的无缝替换标准库(再次,为教学目的),标题包含以下行:
- The header contains a trivially range-checked vector class called
Vector
for teaching purposes; To make
Vector
a "seamless" replacement forvector
in the standard library (again, for teaching purposes), the header contains the following lines:
// disgusting macro hack to get a range checked vector:
#define vector Vector
std_lib_facilities.h
的顶部Google搜索结果),其 Vector
没有 initializer_list
构造函数(该版本使用C ++ 98,没有初始化列表)。 Vector
在看到 vector< int>时没有匹配的构造函数。 v = {1,2,3};
,它变成 Vector< int>
std_lib_facilities.h
), whose Vector
doesn't have an initializer_list
constructor (that edition uses C++98, which doesn't have initializer lists).Vector
doesn't have a matching constructor when it sees vector<int> v = {1,2,3};
, which becomes Vector<int> v = {1,2,3};
after macro replacement.要修复此问题,请下载并使用标题的正确版本。
To fix the problem, download and use the correct version of the header.
这篇关于简单代码需要帮助 - 没有构造函数的实例匹配参数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!