C++11 学习笔记-04.trailing return type
【摘要】
函数声明
以后好好补充把,实在不爱看这一章
#include <iostream>
#include <string>
// 命名空间(文件)作用域中的声明
// (定义在...
函数声明
以后好好补充把,实在不爱看这一章
#include <iostream>
#include <string>
// 命名空间(文件)作用域中的声明
// (定义在后面提供)
int f1();
// 拥有默认实参的简单函数,不返回内容
void f0(const std::string& arg = "world")
{
std::cout << "Hello, " << arg << '\n';
}
// 返回指向 f0 的指针的函数
auto fp11() -> void(*)(const std::string&)
{
return f0;
}
// 返回指向 f0 的指针的函数,C++11 前的风格
void (*fp03())(const std::string&)
{
return f0;
}
int main()
{
f0();
fp11()("test");
fp03()("again");
int f2(std::string); // 块作用域中的声明
std::cout << f2("bad12") << '\n';
}
// 简单的非成员函数,返回 int
int f1()
{
return 42;
}
// 拥有异常说明和函数 try 块的函数
int f2(std::string str) noexcept try
{
return std::stoi(str);
}
catch(const std::exception& e)
{
std::cerr << "stoi() failed!\n";
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
文章来源: yujiang.blog.csdn.net,作者:鱼酱2333,版权归原作者所有,如需转载,请联系作者。
原文链接:yujiang.blog.csdn.net/article/details/106388712
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)