English 中文(简体)
同类目标
原标题:Object of same type as class
  • 时间:2011-10-09 07:41:21
  •  标签:
  • c++
  • object

在C++中,我有的物体与含有的一类物体:

class Test
{
public:

private:
  Test t;
};
问题回答

答案很短,你可以 t。

You can have a pointer to an object of the same type, but not an object itself.

If you NEED to do this (i.e.) can t use a pointer, your design is probably wrong. If you can use a pointer, use it.

www.un.org/Depts/DGACM/index_spanish.htm 某些原因:

你们不得不在瞬时制造这个物体,这意味着对施工者发出明确的休养呼吁。

物体的<代码>sizeof()是什么?

你可以这样做,因为这样做需要无限期的再次入侵。 (Your t将包含另外的t,因此,您有t.t.t.t.t.t.t.t.t.t.t.t.t.t.t. . ad infinitum. 你可以做些什么是把另一个物体放在内,如内。

private:
   Test *t;

问题在于,你写了:

Test t;

编辑needs了解的大小。 测试,以便提供足够的储存。 页: 1 测试编号;:由于汇编者没有看到<代码”定义的结尾,因此,该尺寸为t。 测试(即;> 封闭式>后,从而可以确定其大小。

That s not possible. At the max you can have a reference or pointer of the same class within it.

class Test
{
private:
  Test *t;
};

作为附带说明,<代码> static物体获准。 这是因为它们实际上与任何特定的<代码>}/代码>无关。 反对。 i.e:

class Test
{
private:
  Test t; // error
  static Test st; // ok!
};  // define  st  in the translation unit




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

热门标签