I am trying to use templates intensively for the shell of a factory class:
The wrapping class (that is, classA) receives a wrapped class (such as classB) through a template argument to provide "connectivity".
Also, I have to provide an inner class (innerA) that inherits from the wrapped inner class (innerB).
The problem is the following g ++ error message "gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)":
sebastian@tecuhtli:~/Development/cppExercises/functionTemplate$ g++ -o test test.cpp
test.cpp: In static member function ‘static classA<A>::innerA<iB>* classA<A>::createInnerAs(iB&) [with iB = int, A = classB]’:
test.cpp:39: instantiated from here
test.cpp:32: error: dependent-name ‘classA::innerA<>’ is parsed as a non-type, but instantiation yields a type
test.cpp:32: note: say ‘typename classA::innerA<>’ if a type is meant
As you can see in the definition of the createInnerBs method, I intend to pass a non-type argument. Therefore using typename is wrong!
The test.cpp code is below:
class classB{
public:
template < class iB>
class innerB{
iB& ib;
innerB(iB& b)
:ib(b){}
};
template<template <class> class classShell, class iB>
static classShell<iB>* createInnerBs(iB& b){
return new classShell<iB>(b);
}
};
template<class A>
class classA{
public:
template <class iB>
class innerA: A::template innerB<iB>{
innerA(iB& b)
:A::template innerB<iB>(b){}
};
template<class iB>
static inline innerA<iB>* createInnerAs(iB& b){
return A::createInnerBs<classA<A>::template innerA<> >(b);
}
};
typedef classA<classB> usable;
int main (int argc, char* argv[]){
int a = 5;
usable::innerA<int>* myVar = usable::createInnerAs(a);
return 0;
}
, , .
, ? - ?
,