由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 求教:这个程序为什么不能编译?
相关主题
c++疑难问题。。C++: what is the output? How to interpret it?
C++问题新手问个C++(Thinking in C++ source code)
One C++ questionc++ 程序一问
const_reverse_iterator和reverse_iterator有什么区别?问个面试题
C++ Q83: 这个const_cast什么意思?这个C++程序的运行结果是什么
问个C++模板定义的问题An example of strategy pattern
amazon的那道题目请教C/C++小
one C++ question请教一个c的概念题
相关话题的讨论汇总
话题: tname话题: vector话题: iterator话题: include话题: ii
进入JobHunting版参与讨论
1 (共1页)
y********a
发帖数: 18
1
#include
#include
#include
#include
using namespace std;
template
void printvec( vector vec ) {
cout << "begin--------------------" << endl;
for ( vector::const_iterator it = vec.begin(); it != vec.end();
it++ ) {
cout << setw(10) << *it << endl;
}
cout << "----------------------end" << endl;
}
int main() {
vector vec1;
for ( int ii = 0; ii < 10; ii++ ) {
vec1.push_back( ii );
}
printvec( vec1 );

return( 0 );
}
S**I
发帖数: 15689
2
change vector::const_iterator it = vec.begin(); to
typename vector::const_iterator it = vec.begin();

【在 y********a 的大作中提到】
: #include
: #include
: #include
: #include
: using namespace std;
: template
: void printvec( vector vec ) {
: cout << "begin--------------------" << endl;
: for ( vector::const_iterator it = vec.begin(); it != vec.end();
: it++ ) {

y********a
发帖数: 18
3
能解释一下吗?哪里可以学习相关的知识?谢谢
S**I
发帖数: 15689
4
vector::const_iterator is a qualified dependent type:
qualified: it has "vector::" before it;
dependent: it depends on the template parameter "tname".
keyword "typename" must be added before a qualifed dependent type.

【在 y********a 的大作中提到】
: 能解释一下吗?哪里可以学习相关的知识?谢谢
y********a
发帖数: 18
5
清楚,简洁,明了。
多谢。
1 (共1页)
进入JobHunting版参与讨论
相关主题
请教一个c的概念题C++ Q83: 这个const_cast什么意思?
问个c++题问个C++模板定义的问题
弱问个C++ 问题 (const_cast)amazon的那道题目
面完G的电面了,忐忑one C++ question
c++疑难问题。。C++: what is the output? How to interpret it?
C++问题新手问个C++(Thinking in C++ source code)
One C++ questionc++ 程序一问
const_reverse_iterator和reverse_iterator有什么区别?问个面试题
相关话题的讨论汇总
话题: tname话题: vector话题: iterator话题: include话题: ii