V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  ipwx  ›  全部回复第 4 页 / 共 201 页
回复总数  4017
1  2  3  4  5  6  7  8  9  10 ... 201  
231 天前
回复了 MrLonely 创建的主题 Kubernetes 学不会 k8s 怎么办?
ummm 作为量化交易员你用这个干嘛。

另外 image 和 container 区别需要很久才能理解,你可能需要让你的学习能力进步一点(
231 天前
回复了 shimheeyeon 创建的主题 问与答 Web 远程桌面方案求推荐
Linux 的远程桌面体验和 Windows 是比不上的,因为 Windows 内核有支持,RDP 是发送了控件绘制指令,所以很快;但 Linux 虽然 X11 有绘制指令,可乱七八糟的,所以 VNC 基本等于截图。
235 天前
回复了 Betsy 创建的主题 C++ 求教个 C++ Get 函数怎么写的问题
@lovelylain 你确实 C++ 的细节比我掌握的好,你是个人才。

我只是不推荐楼主去陷入这种不适合工程开发的实践而已。
235 天前
回复了 Betsy 创建的主题 C++ 求教个 C++ Get 函数怎么写的问题
@lovelylain 简单来说,我反对任何形式地依赖这种语义的写法,原因如下:


const A& a = F();


这句话到底会不会产生一个 BUG ,依赖于 F() 的实现。如果 F() 不符合规范中的情形,你这种写法可能会出错。

对于一个工程而言,如果不能在调用方确定上述用法对不对,那就是个灾难。比如

template <typename F>
void someFunction(F&& f) {
const A& a = F();
...
}

当别人复用你的 someFunction 的时候,它就是个隐藏炸弹。

====


@Betsy 27 楼的问题,人家想做的时候照样能够先把 const T& cast 到 const T* 然后 const cast 。。。

想用是拦不住的。
235 天前
回复了 Betsy 创建的主题 C++ 求教个 C++ Get 函数怎么写的问题
@lovelylain “ 返回临时对象,用 const&接收返回值,符合 c++标准,没问题的,编译器会处理声明周期。”

嘿你可真是个人才,还真有这个规范:

https://en.cppreference.com/w/cpp/language/reference_initialization

Lifetime of a temporary

Whenever a reference is bound to a temporary or to a subobject thereof, the lifetime of the temporary is extended to match the lifetime of the reference, with the following exceptions:

a temporary bound to a return value of a function in a return statement is not extended: it is destroyed immediately at the end of the return expression. Such function always returns a dangling reference.
a temporary bound to a reference member in a constructor initializer list persists only until the constructor exits, not as long as the object exists. (note: such initialization is ill-formed as of DR 1696).
(until C++14)
a temporary bound to a reference parameter in a function call exists until the end of the full expression containing that function call: if the function returns a reference, which outlives the full expression, it becomes a dangling reference.
a temporary bound to a reference in the initializer used in a new-expression exists until the end of the full expression containing that new-expression, not as long as the initialized object. If the initialized object outlives the full expression, its reference member becomes a dangling reference.
a temporary bound to a reference in a reference element of an aggregate initialized using direct-initialization syntax (parentheses) as opposed to list-initialization syntax (braces) exists until the end of the full expression containing the initializer.

可是这规范又臭又长,而且 "with the following exceptions" 一不留神就用错。为啥不用肯定没问题、而且编译器会负责优化的返回值拷贝呢?
刚刚在隔壁帖子看到一个 OP 270 满融买 TSLA ,现在大概已经亏 60% 了。

我瞬间觉得 OP 其实亏得挺少的。
@hackyuan 260 满融不止损到现在的位置,你让他 230 懂得退出那也太难为 OP 了。
236 天前
回复了 Betsy 创建的主题 C++ 求教个 C++ Get 函数怎么写的问题
这样,楼主你把 C++ 的引用看成 “指针” 的语法糖就行了。

引用基本就是指针。。。

=====

所以你的第一种,一般可以写成(没有过编译器,手写,不保真):


const Student* Get(const std::string& key) {
auto it = this->map_.find(key);
return (it != this->map_.end()) ? &(it.second) : std::nullptr;
}


然后用的时候

auto myStudent = table.Get("w1");
if (myStudent) {
...
}
236 天前
回复了 Betsy 创建的主题 C++ 求教个 C++ Get 函数怎么写的问题
额其实第二句也是错的

const Student& stu2 = table.Get("s2");

它只能是

Student stu2 = table.Get("s2");

因为你在类里面

Student Get(const std::string& key) { return this->map_[key]; }

它返回的是 this->map_[key]; 的一个拷贝,而不是 this->map_[key]; 它本身的引用。
====


如果你要写成

const Student& stu2 = table.Get("s2");

你对应的类里面应该写成

const Student& Get(const std::string& key) { return this->map_[key]; }
===

楼主对于 C++ 对象的生存周期是完全不理解啊。。。
236 天前
回复了 Betsy 创建的主题 C++ 求教个 C++ Get 函数怎么写的问题
楼主上一个帖子里面也出现了类似的写法

const Status& status = table.Get("w1", &stu1);

这句话是错的。你应该

Status status = table.Get("w1", &stu1);

因为你真的返回的是临时对象啊,这句话执行完就没有了啊(
l=g.eval(e).toString()
238 天前
回复了 Betsy 创建的主题 C++ 求教个神奇的 C++ 打印问题
optional 类似于


template <typename T>
struct Optional {
T* myObject;

Optional() : myObject(nullptr) {}
Optional(const T& value) : myObject(new T(value)) {}
~Optional() { delete myObject; }

bool has_value() { return myObject != nullptr; }
}
238 天前
回复了 Betsy 创建的主题 C++ 求教个神奇的 C++ 打印问题
额,楼主你这

std::optional<ReducedGroupId> GetReduceGroupId(const GroupId& group_id) {
// omit
return std::make_optional<ReducedGroupId>(group_id);
}

不是取了 group_id 的地址塞到 optional 里面。optional 本来就是个完整的对象,所以你是复制了一份 group_id 塞到了 optional 里面。

然后

const ReducedGroupId& reduced_group_id

取的就是这个临时的 optional 内部的 int64 的地址,当然这句话执行完就被 “销毁” 了。后面的代码都是错的。
除了分辨率,显示器还有好多纬度

1. 色彩
2. 刷新率
3. 频闪(护眼)

我猜这个价位的 4k 27 寸 都不行。就看你取舍了
244 天前
回复了 BlAckzkl 创建的主题 生活 谈谈电子阳痿
@BlAckzkl “我跟老婆周末叫上朋友在家打一晚上的麻将,她可没意见。”

这不是回答问题了么。家人需要陪伴,但是无论你的父母还是你老婆,都 get 不到你打的那些游戏的乐趣,所以你没办法陪伴他们,所以他们生气。
244 天前
回复了 BlAckzkl 创建的主题 生活 谈谈电子阳痿
连续长时间的娱乐本来就是脱产者的余裕。

老一代不是有打麻将和钓鱼么。
Transfer-Encoding: chunked
246 天前
回复了 gzldc 创建的主题 随想 真有人在赚我们想不到的钱
“难免感慨一下,这钱赚的.是因为提供情绪价值了吗”

—— 其实掏钱抽卡也是图个一乐,掏钱看手相也是图个吉利而已。没什么高低贵贱。
你这优化是不是只有 windows + 微软雅黑 才是正优化。。。
1  2  3  4  5  6  7  8  9  10 ... 201  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1102 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 37ms · UTC 22:59 · PVG 06:59 · LAX 15:59 · JFK 18:59
Developed with CodeLauncher
♥ Do have faith in what you're doing.