当前位置:网站首页>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))
常
表示我不改
,不变
表示不会变
.
边栏推荐
猜你喜欢
系统结构考点之多级混洗交换网络
手动从0搭建ABP框架-ABP官方完整解决方案和手动搭建简化解决方案实践
Automatically generate test modules using JUnit4 and JUnitGenerator V2.0 in IDEA
When Navicat connects to MySQL, it pops up: 1045: Access denied for user 'root'@'localhost'
基于ABP实现DDD--仓储实践
MySQL cursors
解决npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead
mysql 时间字段默认设置为当前时间
JS中获取元素属性的8大方法
cnpm安装步骤
随机推荐
The most complete Redis basic + advanced project combat summary notes in history
TransGAN代码复现—九天毕昇平台
ClickHouse to create a database to create a table view dictionary SQL
CISP-PTE真题演示
微信公众号授权登录后报redirect_uri参数错误的问题
你需要知道的ES6—ES13开发技巧
导航栏----个人中心 Dropdown
Google Earth Engine ——快速实现MODIS影像NDVI动画的在线加载并导出
解决centos8 MySQL密码问题ERROR 1820 (HY000) You must reset your password using ALTER USER
navicat无法连接mysql超详细处理方法
mysql deadlock
Deep Non-Local Kalman Network for VideoCompression Artifact Reduction
ArrayList扩容机制分析
MySql创建数据表
proxy反向代理
Navicat connection MySQL error: 1045 - Access denied for user 'root'@'localhost' (using password YES)
ML.NET相关资源整理
MySQL 5.7 detailed download, installation and configuration tutorial
使用LVS和Keepalived搭建高可用负载均衡服务器集群
MySQL cursors