I'm learning C++ from a Java background and here is a problem I just met:
Let's say I have a class named A. I use a wrapper called AWrapper. I want A has a link to its wrapper, not just AWrapper but any wrapper. So in Java, I can implement this as below:
public class A {
Object tag;
Object getTag() {
return tag;
}
void setTag(Object tag) {
this.tag = tag;
}
}
and its wrapper:
public class AWrapper {
A a;
public AWrapper(A a) {
this.a = a;
a.setTag(this);
}
}
But in C++, everything is not that simple. First, C++ doesn't have anything as Object in Java. Second, if I don't use Object but AWrapper as return in the getTag(), I will have circular dependency problem. Can anyone show me how to solve this?
Really sorry if my question is dumb, my C++ skill is still poor so any help will be appreciated!