Friday, 15 February 2013

c++ - Replace a variable, by a reference to an element of an array -


I have a class that works properly and an integer as a flag variable (bitwise operation) Uses:

  square foo {uint32_t flags; ...};  

I want to expand this flag to a larger size, for example 512 But I want to make the old code an agnostic work in new shape.

I tried to do this but does not work:

  class foo {uint32_t flags_ext [16]; Uint32_t & amp; Flags = Flag_chests [0]; ...};  

gives me a bunch of problems while asignment. e.t.c. Let me warn of possible double extinction of memory.

The code behaves in any way to behave, but can it be a part of an UTI 32_ T array?

Apply appropriate default, copy maker and assignment operator, and you must be good: / P>

  square foo {uint32_t flags_ext [16]; Uint32_t & amp; Flags; Fu (): Flags (Flag_ext [0]) {} // Copy Seator is not taken into account to copy the reference member Foo (Const Foo and other): Flags (Flag_dest [0]) {:: memcpy ( Flags_ext, other .flags_ext, sizeof (flags_ext)); } Cons Fu & amp; Operator = (Const fee and others) {If (this == and others) returns * This; // do _not_ 'Flags' member copy! :: Memory (Flag_ext, Other.Flags_Ast, Size (Flag_ext)); Return * This; }};  

No comments:

Post a Comment