English 中文(简体)
如何从建筑商内部确定一个等级的记忆定位地址?
原标题:How can a class s memory-allocated address be determined from within the constructor?

Is it possible to get the memory-allocated address of a newly-instantiated class from within that class s constructor?
I am developing a linked list where multiple classes have multiple pointers to like classes. Each time a new class instantiates, it needs to check its parent s list to make sure it is included.

如果我试图这样做的话:

MyClass() // constructor
{
   extern MyClass * pParent;

   for ( int i = 0; i < max; i++ )
   {
      pParent->rels[i] == &MyClass; // error
   }
}

我发现这一错误:

C2275:名称空间:MyClass:非法使用这种表达方式

欢迎任何想法或建议。 感谢。

最佳回答

你指的是:

pParents->rels[i] = this;
问题回答

页: 1

如果你写上某种实例方法,例如:

void MyClass::foo(some params);

汇编者对通过案件地址的方法增加了特别参数。 你们可以想象,汇编者不是上述签字,而是创造这样的东西:

//this is pseudocode
void MyClass::foo(MyClass * const this, some params);

这是原因之一,例如,原因何在。 你们可以直接采用休养方法。

在任何审理方法中,你可以使用一个特别关键词,即作为案件的主人。

静态方法不会使该点人如此。 您可使用其定义中的关键词句

如果有 你们创造了一种像:

class MyClass
{
    void foo(some params);
    void foo(some params) const;
}

就像第二种方法一样。

//this is pseudocode
void MyClass::foo(const MyClass * const this, some params);

汇编者可根据被称作该方法的物体的特性,作出超负荷解决。





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