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 | |
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 | |