Processing is slightly different structures for one function in C++

0 like 0 dislike
7 views
Help the beginner. There are two structures:
struct valuenode { char elements [5]; int power; }; struct indexnode { char elements [5]; int elementindex [10]; };

There is still a function that generates some array structures of the first type (valuenode), here is her announcement:
int pushlevelnodes (valuenode * valuesarray,int beginatindex=0,char toplevel=1) { 

This function uses only the subarray of elements [5], the power is not off. Can this function use in generating an array of structures of the second type? The difference between the structures in the further processing of the values of other functions, the initial array is generated the same way. I would not want to duplicate a fairly large code generation. If you can poke a nose like. Thanks in advance.
by | 7 views

4 Answers

0 like 0 dislike
template method? Or to inherit these two structures from a common ancestor?
by
0 like 0 dislike
union?
by
0 like 0 dislike
Why Byne to do so?
You can function to the input to give an array of char* elements.
And call from valuenode.elements & indexnode.elements.
by
0 like 0 dislike
Create a separate function foo to work with elements [5]. Then create two functions to work with different structures and use them in foo.
by

Related questions

0 like 0 dislike
7 answers
0 like 0 dislike
1 answer
0 like 0 dislike
4 answers
asked Mar 24, 2019 by Hypuk
0 like 0 dislike
3 answers
0 like 0 dislike
7 answers
asked Mar 23, 2019 by kirsan_vlz
110,608 questions
257,186 answers
0 comments
32,758 users