So, as you might have already imagined, I'm trying to use wildcards in C++. But first, let me give you an example of what I mean:
Lets suppose we have a Human class and a Pocket class. The Pocket class has an arbitrary other class as an type argument. To visualize this better, let's write some code (in Java:)
Human.java:
package de.budschie.human_pocket_example;
import java.util.ArrayList;
public class Human
{
ArrayList<Pocket<?>> inventory = new ArrayList<>();
}
Pocket.java:
package de.budschie.human_pocket_example;
public class Pocket<E>
{
E pocketElement;
int amount;
public Pocket(E pocketElement, int amount)
{
this.pocketElement = pocketElement;
this.amount = amount;
}
public E getPocketElement()
{
return pocketElement;
}
public int getAmount() {
return amount;
}
}
As you can see, I can store pockets, regardless of their type argument. I could create a pocket which contains a pocket which contains an Integer, and an other pocket, which contains a Float, and both would fit into the inventory. So, my question is:
How would I do that in C++?
I already tried to use the question mark, but that doesn't seem to have worked. I can't just say, that I want an std::vector<Pocket<?>>.
I hope that this is not off-topic for StackOverflow, and if it is, please tell me in the comments and I'll delete this question as soon as I am able to.