Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //// myheader.cpp
- #include <vector>
- class interface {
- public:
- virtual int& getA() = 0;
- virtual int& getB() = 0;
- virtual int& getC() = 0;
- };
- class interface_impl_X : public interface {
- int a = 0, b = 0, c = 0;
- public:
- interface_impl_X(int aa, int bb, int cc) {
- a = aa;
- b = bb;
- c = cc;
- };
- int& getA() {return a;};
- int& getB() {return b;};
- int& getC() {return c;};
- };
- class interface_impl_Y : public interface {
- int *a, *b, *c;
- public:
- interface_impl_Y(int *aa, int *bb, int *cc) {
- a = aa;
- b = bb;
- c = cc;
- };
- int& getA() {return *a;};
- int& getB() {return *b;};
- int& getC() {return *c;};
- };
- template<>
- class std::vector<interface> {
- public:
- vector<int> a, b, c;
- void push_back(interface &i) {
- a.push_back(i.getA());
- b.push_back(i.getB());
- c.push_back(i.getC());
- }
- interface& operator[](int i) {
- return *(new interface_impl_Y(&a[i], &b[i], &c[i]));
- }
- };
- //// main.cpp
- #include <vector>
- #include "myheader.h"
- using namespace std;
- int main() {
- auto insert = interface_impl_X(1, 2, 3);
- vector<interface_impl_X> AoS;
- AoS.push_back(insert);
- vector<interface> SoA;
- SoA.push_back(insert);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement