English 中文(简体)
您如何在C++中印刷物体的地址?
原标题:How do you print the address of an object in C++?
  • 时间:2012-04-10 15:16:01
  •  标签:
  • c++

如果我有以下基本C++方案:

#include <iostream>
using namespace std;

class CRectangle {
    int x, y;
  public:
    void set_values (int,int);
    int area () {return (x*y);}
};

void CRectangle::set_values (int a, int b) {
  x = a;
  y = b;
}

int main () {
  CRectangle rect;
  rect.set_values (3,4);
  cout << "area: " << rect.area() <<endl;
  cout <<&rect<<endl;
  cin.get();
  return 0;
}

最后一份印刷说明印刷了变式的纸面或物体的地址? 是否相同? 还是这样?

最佳回答

它们是相同的。 它印刷了与物体地址相同的校正地址。 回收也处于停滞状态,因此,整个物体也是一样的。

问题回答

如果说什么意思的话,那就没有上班的地址? 并amp;CRectangle 并不存在,只有一类(加固;撤销)的地址存在。 职等定义本身没有保留记忆。

The variable rect is an object of CRectablge, so there is no difference between the address of the variable and the object in this case.

rect is just an identifier for an object in the stack. In this case, an instance of CRectangle.

通过打电话&rect,请在标的所在处处填写。





相关问题
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?

热门标签