当前位置:网站首页>d违反常了吗
d违反常了吗
2022-07-30 21:46:00 【fqbqrr】
import std;
struct S
{
string s;
void delegate(string s) update;
}
void func(const S* s)
{
//函数接收S常引用,它不能修改S
writeln(*s);
s.update("func");//函数调用闭包的可变引用,来修改.相当于`两层`间接.
writeln(*s);
}
void main()
{
auto s = S("test");
s.update = (_) {
s.s = _; };
//闭包可以修改数据.它持有`可变`引用
writeln(s);
func(&s);
writeln(s);
}
//输出是:
S("test", void delegate(string))
const(S)("test", void delegate(string))
const(S)("func", void delegate(string))
S("func", void delegate(string))
常表示我不改,不变表示不会变.
边栏推荐
- Google Earth Engine ——ee.List.sequence函数的使用
- ClickHouse删除数据之delete问题详解
- 史上最全的Redis基础+进阶项目实战总结笔记
- 深入浅出富文本编辑器
- mysql 时间字段默认设置为当前时间
- MySQL 8.0.29 set and modify the default password
- MySQL删除表数据 MySQL清空表命令 3种方法
- Apache DolphinScheduler新一代分布式工作流任务调度平台实战-
- Day 16 of HCIP
- The most complete Redis basic + advanced project combat summary notes in history
猜你喜欢

面试难题:分布式 Session 实现难点,这篇就够!

JS中获取元素属性的8大方法

The most complete Redis basic + advanced project combat summary notes in history

navicat新建数据库

MYSQL JDBC Book Management System

The reason for not using bs4 is that the name is too long?Crawl lottery lottery information

【Nacos】解决Nacos下载速度缓慢的问题

c语言进阶篇:指针(五)

MySQL Soul 16 Questions, How Many Questions Can You Last?

MySQL 游标
随机推荐
类似 MS Project 的项目管理工具有哪些
3分钟带你了解微信小程序开发
DistSQL in-depth analysis: creating a dynamic distributed database
MySQL压缩包方式安装,傻瓜式教学
8 ways to get element attributes in JS
字节对齐之C语言犄角旮旯的知识
Teach you how to build a permanently running personal server
系统结构考点之并行主存
导航栏----个人中心 Dropdown
MySQL 5.7 detailed download, installation and configuration tutorial
Google Earth Engine ——快速实现MODIS影像NDVI动画的在线加载并导出
Navicat new database
JDBC (detailed explanation)
JUC原子类详解
MySQL cursors
ELF: Loading process
MySQL compressed package installation, fool teaching
LeetCode·Daily Question·952. Calculate Maximum Component Size by Common Factor·Union Check
牛客小白月赛53 A-E
nVisual网络可视化管理平台功能和价值点