V
Vladimir Jovic
Hello,
Next example :
// code
class A
{
public :
typedef int type1;
};
class B
{
public :
typedef int type1;
typedef int type2;
};
template < typename T >
class MyClass
{
typedef typename T::type1 type1;
typedef typename T::type2 type2;
};
int main()
{
MyClass< B > c1;
MyClass< A > c2;
}
// !code
should give next errors when compiled :
g++ s.cpp
s.cpp: In instantiation of ‘MyClass<A>’:
s.cpp:26: instantiated from here
s.cpp:20: error: no type named ‘type2’ in ‘class A’
In my real code, class MyClass is my class, and I can change it, but I
can not change classes A and B. There are more classes with different
number of typedefs, but they all have the same pattern (similar to above) :
class D
{
public :
typedef int type1;
typedef int type2;
typedef int type3;
typedef int type4;
};
Is there a way to typedef type2 in the class MyClass as void, if it not
defined in the template parameter?
Is there a way to make the above example compile?
Thank in advance
Next example :
// code
class A
{
public :
typedef int type1;
};
class B
{
public :
typedef int type1;
typedef int type2;
};
template < typename T >
class MyClass
{
typedef typename T::type1 type1;
typedef typename T::type2 type2;
};
int main()
{
MyClass< B > c1;
MyClass< A > c2;
}
// !code
should give next errors when compiled :
g++ s.cpp
s.cpp: In instantiation of ‘MyClass<A>’:
s.cpp:26: instantiated from here
s.cpp:20: error: no type named ‘type2’ in ‘class A’
In my real code, class MyClass is my class, and I can change it, but I
can not change classes A and B. There are more classes with different
number of typedefs, but they all have the same pattern (similar to above) :
class D
{
public :
typedef int type1;
typedef int type2;
typedef int type3;
typedef int type4;
};
Is there a way to typedef type2 in the class MyClass as void, if it not
defined in the template parameter?
Is there a way to make the above example compile?
Thank in advance