Is there a Perl script to implement C++ Class get/set member functions? -


He mentioned a Pearl script for C ++ programs that helps automate the process of receiving / set () member functions for private data subscribers.

Is anyone aware of such a script and where is it to meet? I'm unable to come up with the right Google keywords to search for it.

Although this does not directly answer your question, you can find that the generated code is In order to manage properties, it is really redundant. The following template code will allow you to easily declare and use properties:

  // My class in class has some properties in my_class {Public: property & lt; Int & gt; X; Property & lt; String & gt; Y; ...}; ... my_class obj; Cout & lt; & Lt; Obj.x (); // obj.y go ("hello, world!"); // set  

Here is the code:

  // The template to choose another form of utility is 1 zero template if it is & lt; Typename t, typename u & gt; Struct replace_void {typedef t type; }; Template & lt; Typename T & gt; Struct replace_void & lt; Zeros, T & gt; {Type ft type; }; // Getter / Setter Template Template & lt; Typename t, typename d = zero & gt; Class property {typedef typename replace_void & lt; D, Property & gt; :: type derived_type; Derived_type & amp; Derived () {return static_cast & lt; Derived_type & amp; & Gt; (* this); } Public: Property () {} // Default CTOR can be safe to leave clear assets (T const & amp; v): _v (v) {} property (property const & amp; p): _v (p) ._v) {} Property & amp; ; Operator = (property b & amp; p) {_v = p._v; Return * This; } T operator () () const {return _v; } // Getter Futile Operator () (T const & v) {generated (). Investigation (v); _v = v; } // Setter protected: // default no-op check (received for override) zero check (T const & v) const {(zero) v; // Avoid unused variable alerts} Private: T _v; };  

check () is a function that tests whether the value assigned is valid. You can override it in a subclass:

  class nonnegative_int: public property & lt; Int, nonnegative_int> {Public: // Unfortunately, all relevant ctors have to be re-prepared: (nonnegative_int (int v): property & lt; int, nonnegative_int> (v) {} zero check (int const & v) const { If (v  

There you have - all the advantages of external recipient generated / setter functions, disturbances None of them!)

You can indicate a validity instead of throwing an exception in an check () one bool .

Edit: As Mr. Fujze Notes you can add a similar method, access in principle. In the comments, the class writer can later change the implementation without modifying the class's logical structure (such as property int member x () methods) , Although binary compatibility is lost, whenever such changes are made, users will need to compile their client code again. This ability to refine the future changes is really the main reason that people use the gator / setter function instead of public members in the first place.

Display Note: Because we're using to get "compile-time polymorphism", any subclass has its own There is no virtual-call overhead to provide check () , and you do not need to declare it as virtual .


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -