Add two structure data of same type and store it finalInstance
#include <iostream>
using namespace std;
typedef struct counter {
int Stx_cnt;
int End_cnt;
int data;
}
counter_t;
class Base {
public:
Base() {}
counter_t firstInstance;
counter_t secondInstance;
};
int main() {
Base obj1;
obj1.firstInstance = {
1,
2,
10
};
obj1.secondInstance = {
3,
4,
20
};
counter_t finalInstance = obj1.firstInstance + obj1.secondInstance;
return 0;
}
I have some data in firstInstance and secondInstance and want to add then and store in finalInstance without accessing through their members and my finalInstance should have {4,6,30};