如果它是静态的,那么“这个”意味着什么 [英] what does 'this' mean if it static

查看:90
本文介绍了如果它是静态的,那么“这个”意味着什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在接受面试,面试官问这个是什么。意思是。

我回答它代表这个类像cout<< a或cout<< this.a

然后他问这是什么意思,如果它是静态的?


我回答说我不太确定但解释我知道静态是什么。

现在我还在想......你觉得答案是什么?


谢谢

解决方案

opistobranchia写道:

我正在面试,面试官问这个是什么意思是。
我回答它代表这个类


它只出现在成员函数的上下文中,并指向

对象调用了成员函数。例如,如果你

调用myObj-> func(),那么在func中,this将等于myObj

(除非一些涉及重载 - >运算符的技巧可以改变

这个;我不确定)。

然后他问这是什么意思,如果它是静态的?


如果什么是静态的? 这个指针? 这个指针不能是静态的。

我回答说我不太确定但解释我知道静态是什么。
现在我还在想......你觉得答案是什么?




如果成员函数是静态的,则没有this指针。


Gregg


GB写道:

opistobranchia写道:

我正在接受面试,面试官问什么是这个。意思是。
我回答它代表了这个类
它只出现在成员函数的上下文中,




应该是

在非静态成员函数的上下文中,

并指向调用成员函数的对象。例如,如果你调用myObj-> func(),那么在func中,this和将等于myObj
(除非一些涉及重载 - >运算符的技巧可以改变这个;我不确定)。

然后他问这是什么意思,如果它是静态的?
如果什么是静态的?




成员函数,傻。

" ;这"指针? 这个指针不能是静态的。

我回答说我不太确定但解释我知道静态是什么。
现在我还在想......你觉得怎么样?答案是?



如果成员函数是静态的,则没有this。终于!


Victor Bazarov写道:

GB写道:

然后他问这是什么意思,如果它是静态的?



如果什么是静态的?



成员函数,傻。




什么成员函数?他没有提到有关会员

功能的任何内容。我不想假设OP知道这个。必须

才能使用会员功能。


Gregg


I was on a job interview and the interviewer asked what "this" meant.
I replied it represented this class like cout << a or cout << this.a
then he asked what this meant if it was static?

I replied I am not really sure but explained I knew what static was.
Now I am still wondering....What do you think the answer was?

Thanks

解决方案

opistobranchia wrote:

I was on a job interview and the interviewer asked what "this" meant.
I replied it represented this class
It is present only in the context of member functions, and points to the
object on which the member function was called. For example, if you
invoke myObj->func(), then within func, "this" will be equal to myObj
(unless some trickery involving overloading the -> operator can change
this; I''m not sure).
then he asked what this meant if it was static?
If what was static? The "this" pointer? The "this" pointer cannot be static.
I replied I am not really sure but explained I knew what static was.
Now I am still wondering....What do you think the answer was?



If a member function is static, there is no "this" pointer.

Gregg


GB wrote:

opistobranchia wrote:

I was on a job interview and the interviewer asked what "this" meant.
I replied it represented this class
It is present only in the context of member functions,



Should be
"in the context of non-static member functions,"
and points to
the object on which the member function was called. For example, if
you invoke myObj->func(), then within func, "this" will be equal to myObj
(unless some trickery involving overloading the -> operator can change
this; I''m not sure).

then he asked what this meant if it was static?
If what was static?



The member function, silly.
The "this" pointer? The "this" pointer cannot be
static.

I replied I am not really sure but explained I knew what static was.
Now I am still wondering....What do you think the answer was?



If a member function is static, there is no "this" pointer.



Finally!


Victor Bazarov wrote:

GB wrote:

then he asked what this meant if it was static?



If what was static?


The member function, silly.



What member function? He did not mention anything about a member
function. I did not want to assume that the OP knows that "this" has to
do with member functions.

Gregg


这篇关于如果它是静态的,那么“这个”意味着什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆