C++ Set object member as reference/pointer of member of a different object? -


(I'm not sure this title is correctly described, because I'm still new to C ++) < / P>

I have two classes, which are loosely presented here:

  class super group {public: layout obz the layout; } Class some class {public: Layout obz my layout; Super Group MyGroup; } During the creator of  some class , I want to set  myGroup.theLayout  to indicate  SomeClass > ' searchout < / Code> Something like this: 

  some class :: some class () {myGroup.theLayout = & amp; MyLayout; }  

Am I doing it correctly? Or do I need to use an indicator? My code starts compiling right, but when I execute it, it crashes, and I can say something with this assignment. Apart from this, I'm not sure if this is incorrectly coded, or if I'm using SDK / API does not like it.

For this reason I have myLayout with super group because I have many methods in SuperGroup , which is used To do myLayout to someClass I'm just trying to avoid passing pass myLayout in the context of those methods right? Is this an easy way to accomplish this?

You really need an indicator to try:

layout obz * theLayout;

Without an indicator, you are trying to assign LayoutObj to a memory address. It can compile, but it is not the behavior you want. Instead, you need an indicator to point to the memory address of LayoutObj .

line myGroup.theLayout = & amp; MyLayout; remains the same.

In the case of C ++ always, be careful that myLayout does not go out before theLayout . If this happens, then you have a hanging indicator, if there is a danger of it, consider using any kind of smart pointer or otherwise adjust your design to adjust it.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -