If I have a variable whose type was a templated class, and I want to build another variable of a different templated class, but use the same template parameter, how could I?
While the example below does not work, it hopefully gives the idea of what I am looking to accomplish. If there is no very specific way to do this, is there a way to have some sort of a lookup table design pattern to do this? There is only six or so different templated types I will probably end up using.
template<typename T>
class A{
public:
typedef T Type;
};
template<typename T>
class B{};
int main(void){
A<int> var1;
B<var1::Type> var2;
}
My apologies if this is a duplicate question, but I did not see anything like this asked before.
EDIT
I would like a way for this to work with Visual Studio 2010 AND gcc, without using a third party library. So not all C++ 11 features may be supported.
Also, without using a typedef A<int> or knowing A<int> as this code is simply a test case scenario to show basic functionality of what I want. I want a way to get the template type from the variable whose type was a template.
Even with VC++ 2010’s pre-standardized decltype, I think you might be able to do something like this:
This depends on being able to form some expression that uses the type you want.