Я изучаю C++ от программирования: принципы и практика с использованием C++/Edition 2, и у меня возникла проблема с векторами. Я использую включенный заголовочный файл, предоставленный из книги Страустрапа here. Когда я компилирую следующую векторную программу, я получаю сообщение об ошибке.Нет сопоставления конструктора для инициализации на Mac
#include "std_lib_facilities.h"
int main()
{
vector<int> v = {5, 7, 9, 4, 6, 8};
for (int i=0; i<v.size(); ++i)
cout << v[i] << endl;
}
Ошибка
vector.cpp:5:21 error: no matching constructor for initialization of 'Vector<int>'
vector<int> v = {5, 7, 9, 4, 6, 8};
^ ~~~~~~~~~~~~~~~~~~
./std_lib_facilities.h:82:5: note: candidate constructor template not viable:
requires 2 arguments, but 6 were provided
Vector(I first, I last) :std::vector<T>(first, last) {}
^
./std_lib_facilities.h:79:14: note: candidate constructor not viable: requires 2
arguments but 6 were provided
Vector(size_type n, const T& v) :std::vector<T>(n,v) {}
^
./std_lib_facilities.h:79:14: note: candidate constructor not viable: requires
single argument 'n', but 6 arguments were provided
explicit Vector(size_type n) :std::vector<T>(n) {}
./std_lib_facilities.h:75:27: note: candidate constructor (the implicit move
constructor) not viable: requires 1 argument, but 6 were provided
template< class T> struct Vector : public std::vector<T> {
^
./std_lib_facilities.h:75:27: note: candidate constructor (the implicit copy
constructor) not viable: requires 1 argument but 6 were provided
./std_lib_facilities.h:78:5: note: candidate constructor not viable: requires 0
arguments, but 6 were provided
Vector() { }
^
Я компиляции с: лязгом ++ -std = C++ 11 -stdlib = LibC++ vector.cpp
Когда я проверяю свою версию Clang, я получаю :
Apple LLVM Version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.1.0
Thread model: posse
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
У меня возникли проблемы с пониманием ошибки и предупреждений и не знаю, куда идти отсюда. Благодарим вас за любую информацию, которую вы можете предоставить.
C++ чувствителен к регистру. –
@KerrekSB Ststustrup 'std_lib_facilities.h' имеет' #define vector Vector'. http://www.stroustrup.com/Programming/std_lib_facilities.h Не могу сказать, что я поклонник этого, хотя ... – krzaq
использовать STL из вашего компилятора –