急:这几行代码怎么理解?
typedef vector<string> rule;
vector<string> entry;
rule(entry.begin()+1,entry.end());
请问
rule(entry.begin()+1,entry.end());返回的是个什么东东?什么类型?
问题点数:0、回复次数:7Top
1 楼taodm((不能收CSDN社区短信息,请莫浪费精力))回复于 2006-12-01 16:46:33 得分 0
rule是一个类型,rule(entry.begin()+1,entry.end());返回是一个临时变量,类型是rule。Top
2 楼HappyTree(笨笨·天行健)回复于 2006-12-01 16:50:12 得分 0
返回的应该是一个vector<string>对象
rule(entry.begin()+1,entry.end());应该是一个对象的构造,其首个元素是entry的第二个元素,最后一个元素是entry的最后一个元素。
Top
3 楼HappyTree(笨笨·天行健)回复于 2006-12-01 16:50:43 得分 0
测试代码
#include <iostream>
#include <vector>
#include <iterator>
#include <string>
using namespace std;
int main()
{
typedef vector<string> rule;
vector<string> entry;
entry.push_back("aaaaa");
entry.push_back("bbbbb");
entry.push_back("ccccc");
entry.push_back("ddddd");
entry.push_back("eeeee");
cout << "entry: ";
copy(entry.begin(), entry.end(), ostream_iterator<string>(cout, " "));
cout << endl;
rule a = rule(entry.begin()+1,entry.end());
cout << endl;
copy(a.begin(), a.end(), ostream_iterator<string>(cout, " "));
cout << endl;
return getchar();
}Top
4 楼lihongbin33(乳沟就象时间,挤挤还是有的)回复于 2006-12-01 19:41:25 得分 0
3kissTop
5 楼htqx(航天奇侠)回复于 2006-12-01 19:59:01 得分 0
typedef vector<string> rule;
vector<string> entry;
rule 就是 vector<string>
相当于:
vector<string> entry;
vector<string> entry2( entry.begin() + 1, entry.end() );
就是一个初始化的调用而已。
Top
6 楼A553990(黑暗中摸索~)回复于 2006-12-02 11:51:14 得分 0
rule(entry.begin()+1,entry.end());
这个是一个初始化吧?
我也不太明白?
是不是 应该有一个 名字?
比如
rule entry2 (entry.begin()+1,entry.end());
Top
7 楼taodm((不能收CSDN社区短信息,请莫浪费精力))回复于 2006-12-04 08:54:02 得分 0
一个临时变量,没有名字。Top





