由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 问两个问题,C++
相关主题
【C++】请问这样有没有memory leak?多谢why use static function here?
问题: C++ static_cast between int and floatC++: operator new 为啥要是 static的, 不是有啥影响?
c++里面caveats太多了What're the three types of memory allocated for C++ variables?
some C++ interview questionstempalte as the overloaded conversion operator
C++ cast 小结operator overloading (C++)
this和&*this的区别求教new delete 在c++中的重载
请教个static_cast vs reinterpret_cast的问题。弱问一下
国内的编程论坛很不自由请教个Bloomberg 的 C++ 题目
相关话题的讨论汇总
话题: rwtime话题: static话题: cast话题: object话题: temporary
进入Programming版参与讨论
1 (共1页)
v*********o
发帖数: 5
1
一、受保护的析构函数有什么作用?
二,下面的表达式有什么区别?
static_cast(*this) += 5
static_cast(*this) += 5
谢谢大家
t****d
发帖数: 8
2
讨论一下,我的理解不知道对不对。

这样不能在栈里生成该类的对象,因为destructor不能正常调用。
只能生成其子类的对象,同样的原因。
operator +=是个函数,第一个参数是pass by reference 还是pass by value

【在 v*********o 的大作中提到】
: 一、受保护的析构函数有什么作用?
: 二,下面的表达式有什么区别?
: static_cast(*this) += 5
: static_cast(*this) += 5
: 谢谢大家

W*********g
发帖数: 409
3
static_cast(*this) += 5
A temporary object will be created, and "this" object will not be changed.
static_cast(*this) += 5
No temporary object created, and the "RWTime" part of "this" object will
be changed (Provided that operator+= is not virtual).
c********x
发帖数: 84
4

I disagree.
static_cast(*this) += 5
the object itself pointed by *this add 5;
static_cast(*this) += 5
the object allias pointed by *this add 5;

【在 W*********g 的大作中提到】
: static_cast(*this) += 5
: A temporary object will be created, and "this" object will not be changed.
: static_cast(*this) += 5
: No temporary object created, and the "RWTime" part of "this" object will
: be changed (Provided that operator+= is not virtual).

1 (共1页)
进入Programming版参与讨论
相关主题
请教个Bloomberg 的 C++ 题目C++ cast 小结
[C++] when destructors get calledthis和&*this的区别
Re: can destructor be static?请教个static_cast vs reinterpret_cast的问题。
A question about singleton国内的编程论坛很不自由
【C++】请问这样有没有memory leak?多谢why use static function here?
问题: C++ static_cast between int and floatC++: operator new 为啥要是 static的, 不是有啥影响?
c++里面caveats太多了What're the three types of memory allocated for C++ variables?
some C++ interview questionstempalte as the overloaded conversion operator
相关话题的讨论汇总
话题: rwtime话题: static话题: cast话题: object话题: temporary