S
Siegfried Weiss
Hi guys,
i give up finding a solution by reading or by trial & error. Hope, YOU
can help me! (Sorry for my rather long posting.)
Stroustrup says, that templates could be declared with
- type parameter, e.g. template<class T>
- parameters with *simple* types like int, e.g. template<int size>
- template parameter, e.g. template< template<class> class A >
the latter beeing a type specifier, not an instance of A.
So, there is no way to declare a template class with an *object* of my
own (template) class A ??
I want to declare a template class giving it a template object as a
template parameter:
// an instance of such a class should be a template parameter
template <class T>
class A {
public:
typedef T data_type_A;
...
};
// the template, which gets an object of type A<> as a template parameter
// the syntax is (not yet) correct (that exactly is my problem)
template <template<class> A theObjectOfA> // <<< the problem
class B {
public:
// an obj of A, type <T> doesn't matter
const template<class> A &mA;
// the type <T> of A is used only here
typedef typename theObjectOfA::data_type_A data_type_B;
B() : mA( theObjectOfA) {}
...
};
In the above line in question, i want to express, that
- theObjectOfA is a parameter for the template - not beeing
of a *simple* type line an int - and
- theObjectOfA could be of ANY type T, so T should not be specified
here. Later, when i use this class, the compiler knows the Type T
of the given object.
How can i achieve this ?
The reason, why i want to accomplish this is: there should be defined
MANY (static) objects of derived B's, each will be given a (static)
object of A as parameter:
class C : public B<obj_1_OfA> {
public:
C() : B<obj_1_OfA>() {}
};
The class C must have in common the datatype T of objOfA. Because the
compiler knows the class T of A, why shouldn't i use his knowledge.
I could solve the problem, if B would be declared like:
template <class T>
class B {
public:
typedef T data_type_B;
const A<T> mA;
B(const A<T> &theObjectOfA) : mA( theObjectOfA ) {}
...
};
Then, C must be written as:
class C : public B<anyClassT> {
public:
C() : B<anyClassT> (anObjectOfA_forClassT) {}
};
But then I must care to use the same type T for C and the argument for
B::B().
Thx for any advice.
Siggi.
i give up finding a solution by reading or by trial & error. Hope, YOU
can help me! (Sorry for my rather long posting.)
Stroustrup says, that templates could be declared with
- type parameter, e.g. template<class T>
- parameters with *simple* types like int, e.g. template<int size>
- template parameter, e.g. template< template<class> class A >
the latter beeing a type specifier, not an instance of A.
So, there is no way to declare a template class with an *object* of my
own (template) class A ??
I want to declare a template class giving it a template object as a
template parameter:
// an instance of such a class should be a template parameter
template <class T>
class A {
public:
typedef T data_type_A;
...
};
// the template, which gets an object of type A<> as a template parameter
// the syntax is (not yet) correct (that exactly is my problem)
template <template<class> A theObjectOfA> // <<< the problem
class B {
public:
// an obj of A, type <T> doesn't matter
const template<class> A &mA;
// the type <T> of A is used only here
typedef typename theObjectOfA::data_type_A data_type_B;
B() : mA( theObjectOfA) {}
...
};
In the above line in question, i want to express, that
- theObjectOfA is a parameter for the template - not beeing
of a *simple* type line an int - and
- theObjectOfA could be of ANY type T, so T should not be specified
here. Later, when i use this class, the compiler knows the Type T
of the given object.
How can i achieve this ?
The reason, why i want to accomplish this is: there should be defined
MANY (static) objects of derived B's, each will be given a (static)
object of A as parameter:
class C : public B<obj_1_OfA> {
public:
C() : B<obj_1_OfA>() {}
};
The class C must have in common the datatype T of objOfA. Because the
compiler knows the class T of A, why shouldn't i use his knowledge.
I could solve the problem, if B would be declared like:
template <class T>
class B {
public:
typedef T data_type_B;
const A<T> mA;
B(const A<T> &theObjectOfA) : mA( theObjectOfA ) {}
...
};
Then, C must be written as:
class C : public B<anyClassT> {
public:
C() : B<anyClassT> (anObjectOfA_forClassT) {}
};
But then I must care to use the same type T for C and the argument for
B::B().
Thx for any advice.
Siggi.