Basically, what I want to do is something like this:
template<typename x,typename y,typename z>
struct SomeTemplateClass {
typedef x myType;
};
then...
SomeTemplateClass<LongVariableNames,ILikePie,AndCheese> cheese;
cheese.myType i;
So i
will have the type LongVariableNames
.
I know it's probably bad practice to do stuff like this, but I just want to know. What's the simplest way to do something like this?
I mean, it should be possible to resolve this at compile time easily, because of the strong static typing and such. It would be useful to have a typeof()
thing just like sizeof()
.
Typically it goes like this:
typedef SomeTemplateClass<LongVariableNames,ILikePie,AndCheese> foodType;
foodType cheese;
foodType::myType i;
In C++11 you could also use decltype(cheese)::myType
, but that's very ugly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.