首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

一个关于引用和返回值得有关问题

2012-02-08 
一个关于引用和返回值得问题主要程序:typedefpair short,shortlocationtypedefvector locationlocty

一个关于引用和返回值得问题
主要程序:
typedef   pair <short,short>   location;
typedef   vector <location>   loc;
typedef   vector <string>   text;
typedef   pair <text*,loc*>   text_loc;


text_loc*   separate_words(const   vector <string>   *text_file)
{
vector <string>   *words=new   vector <string> ;
vector <location>   *locations=new   vector <location> ;
.......
return   new   text_loc(words,locations);
}


怎么函数返回值是text_loc*类型
而return的是new   text_loc(words,locations),这是个指针吗?

[解决办法]
new了一个对象
返回的是首地址的指针
[解决办法]
new得到的东西就是指针啊。这个函数利用pair返回了两个指针,tuple是不是更合适一点?

热点排行
Bad Request.