English 中文(简体)
标语
原标题:Object calling an object

某人可以向我解释<代码>(*this)点,并表明如何将其用作同一类别另一物体的物体。 我不理解的是,你将如何在两个不同目标的成员职能中以相同的变数提及两个数字。 例如,增加两个数字。

a.Multiply(b);
//....
Numbers::Numbers Multiply(Numbers auggend)
{
}
最佳回答
this pointer:

每一物体的成员职能可进入一个标明物体本身的点名this。 当我们称之为成员职能时,它就存在,其价值为>、。 使用<条码>该指任何成员均可找到其所属物体的地址。 也可使用该数据获取其标的中的数据。 例:

void setdata(int ii)
{
   i=ii;         // one way to set data
   this->i=ii;   // another way to set data
}
问题回答

http://www.un.org/Depts/DGACM/index_french.htm

(* )是你宣布某类人的一个要点。 举例来说,如果数字类别具有数据价值“价值”:

a.Multiply(b);
....
Numbers::Numbers Multiply(Numbers auggend)
{
  return (this->value) * (auggend.value);
}

首先,你的例子并不正确。 我认为应该:

Numbers Numbers::Multiply(Numbers auggend)
{
}

如上所述,<代码>该只是一个类型的变量:<代码>Numbers * const,标明了你的成员变量。 因此,根据您的榜样,a.Multiply(b),this将具有&a的价值。

请允许我说,你还有其他一些职能,采用了<代码>。 编号*:

void DoSomething(Numbers *num);

之后,你可以把这一职能称作this:

Numbers Numbers::Multiple(Numbers auggend)
{
    DoSomething(this); 
    DoSomething(&auggend);
}
class A{
   int num;
   void foo(int num)
   {
      num = 10; //local variable num is set to 10
      this->num = 10 ; //class member num is set to 10
   }
};




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签