D
desktop
I am trying to understand the use of this template and how to use it:
// Primary template.
template<bool C, typename Ta, typename Tb>
class IfThenElse;
// Partial specialization, true.
template<typename Ta, typename Tb>
class IfThenElse<true, Ta, Tb> {
public:
typedef Ta ResultT;
};
// Partial specialization, false.
template<typename Ta, typename Tb>
class IfThenElse<false, Ta, Tb> {
public:
typedef Tb ResultT;
};
int main() {
IfThenElse<true,std::string,int> iff;
std::string str = iff.ResultT;
return 0;
}
When instantiated with true it should typedef the second argument
(std::string) to the public fieldResultT. But in main() I get an error
when I try to check the type of ResultT. Why is it not possible to
access ResultT?
// Primary template.
template<bool C, typename Ta, typename Tb>
class IfThenElse;
// Partial specialization, true.
template<typename Ta, typename Tb>
class IfThenElse<true, Ta, Tb> {
public:
typedef Ta ResultT;
};
// Partial specialization, false.
template<typename Ta, typename Tb>
class IfThenElse<false, Ta, Tb> {
public:
typedef Tb ResultT;
};
int main() {
IfThenElse<true,std::string,int> iff;
std::string str = iff.ResultT;
return 0;
}
When instantiated with true it should typedef the second argument
(std::string) to the public fieldResultT. But in main() I get an error
when I try to check the type of ResultT. Why is it not possible to
access ResultT?