P
poliklosio
If you look at the following code:
#include <iostream>
using namespace std;
struct FormatType
{
typedef char char_type;
};
template<class CharT>
struct A
{
typedef CharT ggg;
};
template<class FormatT>
struct B
ublic A<typename FormatT::char_type>
{
//this has to be explicit... what a shame
typename A<typename FormatT::char_type>::ggg g;
};
int main() {
B<FormatType> b;
cout<<b.g<<endl;
return 0;
}
Why does the line
typename A<typename FormatT::char_type>::ggg g;
have to be so explicit, instead of just saying
ggg g;
?
I use G++ 4.4.1
I thought I could avoid repeating some typedefs (in multiple classes
similar to B above) by inheriting from a class which defines them
(class A above), but apparently that requires writing them very
verbosely, which completely defeats the advantages. Why?
#include <iostream>
using namespace std;
struct FormatType
{
typedef char char_type;
};
template<class CharT>
struct A
{
typedef CharT ggg;
};
template<class FormatT>
struct B
{
//this has to be explicit... what a shame
typename A<typename FormatT::char_type>::ggg g;
};
int main() {
B<FormatType> b;
cout<<b.g<<endl;
return 0;
}
Why does the line
typename A<typename FormatT::char_type>::ggg g;
have to be so explicit, instead of just saying
ggg g;
?
I use G++ 4.4.1
I thought I could avoid repeating some typedefs (in multiple classes
similar to B above) by inheriting from a class which defines them
(class A above), but apparently that requires writing them very
verbosely, which completely defeats the advantages. Why?