一个关于引用和返回值得问题
主要程序:
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是不是更合适一点?