C++ “促进事业”;类模板的模板参数太少';向量'&引用;
我有一个简单的程序:C++ “促进事业”;类模板的模板参数太少';向量'&引用;,c++,boost,C++,Boost,我有一个简单的程序: #include <vector> #include <iostream> #include "boost/unordered_map.hpp" int main() { std::vector<unsigned char> v; v.push_back('a'); std::cout << "Hello " << v[0] << std::endl; } 我得到这个错误:
#include <vector>
#include <iostream>
#include "boost/unordered_map.hpp"
int main() {
std::vector<unsigned char> v;
v.push_back('a');
std::cout << "Hello " << v[0] << std::endl;
}
我得到这个错误:
vec.cpp:6:10: error: too few template arguments for class template 'vector'
std::vector<unsigned char> v;
^
/usr/local/include/boost/detail/container_fwd.hpp:86:47: note: template is declared here
template <class T, class Allocator> class vector;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
vec.cpp:6:10:错误:类模板“vector”的模板参数太少
std::向量v;
^
/usr/local/include/boost/detail/container_fwd.hpp:86:47:注意:模板在这里声明
模板类向量;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
从C++文件中删除“包含Boost”行删除错误。我使用的是OS X 10.10.3,如果有什么不同的话,我使用自制软件安装了boost。据我所知,boost似乎正在将向量模板覆盖为非标准的内容?对此我能做些什么?
无法在Linux上使用gcc/stdlibc++和clang/libc++复制。这是哪个版本的boost?您确定要按照指定的顺序(在/usr/local/include/boost/detail/container\u fwd.hpp之前)包含这些内容吗?也许可以尝试使用
作为良好的衡量标准,在我的系统上运行良好,与OS X 10.10.3、boost 1.57.0相同。您是如何安装boost的?我认为这可能是一个问题,自制,它说版本1.57.0,但可能是有问题的安装。我同意祖母绿。boost的安装似乎有问题。您在OSX上安装了boost,但关键代码模板类向量;位于#ifdef块中,该块仅在定义BOOST_MSVC时编译。你的程序是用g++而不是用clang++编译的吗?
vec.cpp:6:10: error: too few template arguments for class template 'vector'
std::vector<unsigned char> v;
^
/usr/local/include/boost/detail/container_fwd.hpp:86:47: note: template is declared here
template <class T, class Allocator> class vector;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^