Pointer as a member or reference as a member

I need one clarification in C ++ linux.

I have class C1one more class C2. C1will have a link C2.

class C1
{

   C2 &obj ;

}

I think of two options here,

  • Directly holding the link C2asC2 &obj;
  • Creating a pointer C2likec2* obj;

What well? what is the difference? when do you choose either?

+5
source share
4 answers

Avoid using the reference element as much as possible.

, ,
, , , , NULL , - , C2 , .

, . , , (=), . , =.

( - C2), C2 C1, , , /, .

, , , , .

+3

. , (, ++). . C2 , C1, , , .

Als, , C2 . , , " " .

0

. - , -, , , .

, , - - . (, ++ Builder / VCL .)

, , - C- ++ .

, , - - . , , , .. const *c2 const obj;

, , , , , .

: , , - , , , - .

0

, , .

, - , - . . , .

, .

0

All Articles