Redian新闻
>
求教:这个程序为什么不能编译?
avatar
求教:这个程序为什么不能编译?# JobHunting - 待字闺中
y*a
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 );
}
avatar
S*I
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++ ) {

avatar
y*a
3
能解释一下吗?哪里可以学习相关的知识?谢谢
avatar
S*I
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 的大作中提到】
: 能解释一下吗?哪里可以学习相关的知识?谢谢
avatar
y*a
5
清楚,简洁,明了。
多谢。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。