title: How to register a variable from within the class definition in the header file c++
body: <p>I'm working on some code where the getters and setters of a class are created using a macro. Something like</p>
  
  <pre><code>class MyClass : MyStruct
  {
      MEMBER(m_member1);
      MEMBER(m_member2);
      MEMBER(m_member3);
      MEMBER(m_member4);
      MEMBER(m_member5);
  }
  </code></pre>
  
  <p>where MEMBER is a macro that creates a setter and getter for the members which are defined in the MyStructBase.</p>
  
  <p>I want to modify the MEMBER macro to add some kind of registration for each member. So that in addition to creating setters and getters, the MEMBER macro also does something like calling m_myRegistry.register(Member1) for each member. Essentially being able to register each member of the class without having to rewrite the code (we have a very large number of this MyClass classes so would save a lot of work if I only have to modify the macro and no the constructors of the classes).</p>
  
  <p>So, my question is, is there a way to call a function from within the class definition to solve this problem? I'm thinking it might be possible by declaring a static class that's template specialised on the actual member, but I can't think how to do it.</p>
  
  <p>Edit: I have been asked to show the macro used. It's quite complex and I'm not sure if my company would be particularly happy for me to post their code on stack overflow, so I'm going to post a simplified version of it:</p>
  
  <pre><code> #define MEMBER(membername)
      // some boost magic to typdef membername##traits::Type to the type of membername
      ...
      //
      membername##traits::Type get##membername()
      {
          return membername;
      }
      void set##membername(const membername##traits&amp; a)
      {
           membername = a;
      }
  </code></pre>
  
  <p>So what I want is to modify the macro to do something like:</p>
  
  <pre><code> #define MEMBER(membername)
      // some boost magic to typdef membername##traits::Type to the type of membername
      ...
      //
      membername##traits::Type get##membername()
      {
          return membername;
      }
      void set##membername(const membername##traits&amp; a)
      {
           membername = a;
      }
  
      m_objectRegistry.register(membername);
  </code></pre>