c++primer 6.3.3节练习(返回数组指针的4个方法)

#include <iostream>  
#include <string>
#include <vector>
using namespace std;
/*返回数组指针或者引用的4种方法*/
/*返回数组指针,方法1,类型别名*/
using arryS = string[10];
arryS& func1();

/*返回数组指针,方法2,声明函数(较为繁琐,不易理解)*/
string(&func2())[10];

/*返回数组指针,方法3,尾置返回类型*/
auto func()->string(&)[10];

/*返回数组指针,方法4,使用decltype(已知返回数组指针指向那个数组)*/
string test[10] = { "a", "b", "c" };
decltype(test) &func();


4种声明返回数组指针函数的方法,其中第2个方法较为繁琐,不易理解,不推荐。

发布了54 篇原创文章 · 获赞 14 · 访问量 1万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章