I'm confused with a lot of answers found about what is a simple thing in other languages. I would like to get a reference to an object contained in class or struct. I've come up to using one of two different functions (here - getData()).
Question:
So, I am not sure which one to use, they appear to do the same thing. Other thing, is there some reason I should care because it's a union? And the most important question here is - I'm not sure about delete part I found in some answers, which scares me that this code example I've shown is not complete and will cause some memory leaks at some point.
#include <iostream>
#include <stdint.h>
using namespace std;
class settings_t {
  private:
  static const  long b1 =0;
    uint8_t setmap;
  public:
    uint8_t myBaseID; 
    uint8_t reserved1;
    uint8_t reserved2;
};  
class test1 {
  public: //actually, I want this to be private
    long v1;
    settings_t st;
    union {
      uint8_t data[4];
      uint32_t m1;
      settings_t st1;
    };
  public:
    uint8_t * getData() {
      return data;
    }
    uint8_t (&getData2())[4] {
      return data;
    }
};
int main() {
  test1 t1;
  t1.data[2]=65;
  uint8_t *d1 = t1.getData();
  cout<<" => " << d1[2];
  d1[2]=66;
  uint8_t *d2 = t1.getData2();
  cout<<" => " << d2[2];
}