OOP proposal about having two instances of the same class on another
This has caused me great headache, making me delete well-working code to write another and then return to the first and so on.
Code:
class X();
class A{
int key;
X *n, *p;
public:(some methods here)
};
Now, I want to make a class B, with two ints, and four pointers, this time pointing to n(ext), p(revious), (u)p,d(own). (Note: my real task is making a sparse array). You'll notice this is two sets of class A, and indeed I need each set to have the same method class A has for it. From what I've read, I have the following options:
Code:
1)class from scratch containing all data/methods
class B{
int key1,key2;
X *n,*p,*u,*d;
public:(previous methods, and a copy+search->replace of them for key2/u/d)
}
2)class containing classes
class B{
A c1,c2;
}
3)class inheriting one and containg other:
class B:public A{
A c2;
}
4)class inheriting both, using :: in methods to rid ambiguity:
class A1:public A{};
class A2:public A{};
class B:public A1,public A2{};
What should I do? 1) sounds silly to me, because isn't OOP meant to avoid copy-pasting? 2) sounds better, but can I not avoid having an additional . operator all the time? 3) seems very asymmetrical to me. 4) seems good, but I have to type classname:: which IS long, plus it invokes fear in me because I see I can manipulate private vars.
What should I choose and why? And if there is another way, please do tell! Thanks!