Reputation: 329
I got the following challenge.
I got a template class that defines a boost shared_ptr as a type.
template<typename T, int a, int b>
class AbstractSmth{
public:
typedef boost::shared_ptr< AbstractSmth > ABSTR_SMTH;
...
};
and an other also template class, in which I want to use that type. I know the following syntax works.
template<typename T, int a, int b>
class AbstractOtherThing{
public:
typename AbstractSmth<T,a,b>::ABSTR_SMTH p_smth;
void myFancyFunction(typename AbstractSmoother<T,a, b>::ABSTR_SMTH baz){
...
}
};
Is it possible to use that type as a typedef inside that class? Maybe something like this:
template<typename T, int a, int b>
class AbstractOtherThing{
public:
using typename AbstractSmth<T,a,b>::ABSTR_SMTH;
ABSTR_SMTH p_smth;
void myFancyFunction(ABSTR_SMTH baz){
...
}
};
Best regards and happy new year!
Upvotes: 1
Views: 3247
Reputation: 55395
Sure.
Oldschool:
typedef typename AbstractSmth<T,a,b>::ABSTR_SMTH ABSTR_SMTH;
C++11:
using ABSTR_SMTH = typename AbstractSmth<T,a,b>::ABSTR_SMTH;
Upvotes: 9
Reputation: 217135
You want:
typedef typename AbstractSmth<T,a,b>::ABSTR_SMTH ABSTR_SMTH;
or C++11 way:
using ABSTR_SMTH = typename AbstractSmth<T,a,b>::ABSTR_SMTH;
Upvotes: 2