Re: About class constructores with templates
On 17 Nov., 00:05, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:
hi All ,
I am giving the pseudo code about the problem I am talking about .
I have a class hiearchy which looks like this.
class A;
template <class X1, class X2> class B : public A{}
template <class X3> class C: public B<Xreal1, Xreal2>;
The syntax of what you attempt above is
template <class X3,class Xreal1,class Xreal2> class C: public
B<Xreal1, Xreal2>;
Now is it necessary to put the following statement before the line
above like the following
template <Xreal1, Xreal2> class B;
Yes it is - you have to declare B before you can use it!
Anyway, the line "template <class X3> class C: public B<Xreal1,
Xreal2>;" is already showing the path to this hierarhcy,
And also, why do that have to instantiate the class B when you are
talking about the class C.
Surely any instantation of class C must instantiate class B? If you
dont believe so, your expectations are wrong. You could declare the
class without instantiating it, of course:
template <Xreal1, Xreal2> class B;
template <class X3,class Xreal1,class Xreal2> class C: public
B<Xreal1, Xreal2>;
Since I am getting g++ compilation errors due to it.
I am not able to give the code out as it is too sphegtti type and get
some people confused ( like I did )
If you are confused already know, you should take it as a hint that
the code needs a rewrite. Just imagine how confused you will be if you
look at the code again in six months (not to mention if it becomes the
job of a collegue of yours).
/Peter