is a code, which we are trying to convert to C ++ code. There were two heritage hierarchies, which were managed by C through the switch .. It has been converted to use the virtual function in C ++. At one point these two hierarchies have to be related. For example class A is related to A1, class is related to BB1. Where A, B, C, Hybrid 1 and A1, B1, C1 fall into hierarchy 2. In C code, it can be achieved by storing the tag field of hierarchy 2 (or the type area used in the switch area) in A, B, C. Can anyone get me this C ++ properly?
C
Enum node tag 1 {A_Node, B_net ....}; Enum node tag 2 {A1_Node, B1_Node ....}; Structure node {node tag 1 tag1; }; Structure A {node tag 1 tag 1; Node tag 2 tag2; ..other members... };
Straight B, C all look the same.
Now suppose that there are 10 functions (F1, F2 ..) which use nodagag 1 to switch. Case in C ++
< Code> class node {// 10 virtual functions (F1, F2 ..)}; Class A: Public Node {// 10 Virtual Function (F1, F2 ..)}; Class B: Public Node {// 10 Virtual Function (F1, F2 ..)};
Now there is a function like this, which is said by the examples of hierarchy 1.
int fixed (node tag 2 tag2) {switch (tag2) {...}}
How do I get it in C ++ Can i
Thank you, Gokul.
If you do not want to create objects at run time, you can use the following method. With the creation of an item only once you do not have to reach the members of the classes, the single object will work for you;
class A {public: virtual f () {printf ("A"); } Fixed A * behaveLikeA (); Fixed A * behaveLikeB (); }; Class B: Public A {Public: Virtual F () {printf ("B"); }}; A * A :: behaveLikeA () {Fixed A AG; Return and AG; } A * A :: behavioral BB () {stable bg; Return and BG; }; Int main (int argc, char * argv []) {a * b :: a :: behaveLikeB (); B & gt; F (); B = A: behavioral (); B & gt; F (); Return 0; }
Comments
Post a Comment