Re: PLEASE HELP : Template inheritance problem gcc 3.2.3
From: Buster (none_at_none.com)
Date: 12/06/04
- Next message: Stephen Sprunk: "Re: [OT] Using hobby source code in your job ?"
- Previous message: Morgan Cheng: "Re: Is this good style of C++?"
- In reply to: Gandu: "PLEASE HELP : Template inheritance problem gcc 3.2.3"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 06 Dec 2004 02:35:17 +0000
Gandu wrote:
> Could some C++ guru please help me. I have a template based general linked list
> class that I want to inherit publicly to create a queue class. In the case of
> non-template inheritance, I can use:
> class A{ };
> class B: public A{};
>
> And for the constructor of B:
> B:B():A(){}
>
> now suppose I have a template as:
> template <class T>
> class A{ ... };
>
> template <class T>
> class B: public A<T>{ ... }
>
> What is the syntax for the constructor of B in this case, i.e., what goes into
> the following - where the question marks are?
>
> template <class T>
> B<T>::B():???????{}
>
> Thanks in advance for your help!!
What Jonathan said (move the constructor definition inside the class
definition, which has the side effect of making the constructor inline),
or ...
template <typename T>
struct A
{
A (/* parameters for A */);
};
template <typename T>
struct B : A <T>
{
B (/* parameters for B */);
};
template <typename T>
A <T>::A (/* parameters for A */) { }
// ... like this:
template <typename T>
B <T>::B (/* parameters for B */) : A <T> (/* arguments for A */) { }
void test_syntax ()
{
B <int> b (/* arguments for B */);
}
-- Regards, Buster
- Next message: Stephen Sprunk: "Re: [OT] Using hobby source code in your job ?"
- Previous message: Morgan Cheng: "Re: Is this good style of C++?"
- In reply to: Gandu: "PLEASE HELP : Template inheritance problem gcc 3.2.3"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|