返回数组的引用
#include <iostream>#include <string>
using namespace std;
string (& str(string s));
typedef string sss;
sss& str1(string s);
auto str2(string s)->string(&);
string s1;
decltype(s1)& str3(string s);
大佬看看是否都是等价的函数声明 是 $ cat main.cpp
#include <iostream>
#include <string>
//using namespace std;
using std::string;
string (&str(string s));
typedef string sss;
sss &str1(string s);
auto str2(string s) -> string (&);
string s1;
decltype(s1) &str3(string s);
using std::cout, std::endl;
int main() {
cout << typeid(str).name() << endl;
cout << typeid(str1).name() << endl;
cout << typeid(str2).name() << endl;
cout << typeid(str3).name() << endl;
return 0;
}
$ g++-debug -o main main.cpp
$ ./main
FRA10_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_E
FRA10_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_E
FRA10_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_E
FRA10_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_E
$ ./main | c++filt -t
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (&(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (&(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (&(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (&(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))
$
页:
[1]