[问题] C++ class this问题

楼主: anoymouse (没有暱称)   2014-11-22 02:14:53
书上写
class time{
private:
int hour;
public:
void set(int h){this->hour=h;}
void print(){cout<<this->hour;}
};
想请教一下this指标 上述两行的this是隐藏参数 可是没有传this进来
在里面却有this 感觉很奇怪
还是说其实有 像void print(time *this){cout<<this->hour;} 只是也隐藏起来了?
作者: cjcat2266 (CJ Cat)   2014-11-22 02:43:00
member function都会隐晦地传进this pointer更正,non-static member functions
楼主: anoymouse (没有暱称)   2014-11-22 02:44:00
所以是像我最后一行这样传进吗?
作者: cjcat2266 (CJ Cat)   2014-11-22 03:34:00
是的
作者: CaptainH (Cannon)   2014-11-22 11:13:00
型态是 T * const
楼主: anoymouse (没有暱称)   2014-11-22 12:01:00
请问T是什么?
作者: koka813 (shift)   2014-11-22 13:47:00
template吧,想表达的意思大概就该class型别的pointer
作者: LPH66 (-6.2598534e+18f)   2014-11-22 14:56:00
嗯, 以及这个 this 指标不能被改指 (它是 const pointer)
楼主: anoymouse (没有暱称)   2014-11-22 16:13:00
好 我再看看有问题再问 谢谢各位!
作者: Killercat (杀人猫™)   2014-11-26 04:09:00
this是keyword 意思就是“自己这个实体”

Links booklink

Contact Us: admin [ a t ] ucptt.com