how to call an inherited, template class constructor from initializerlist of an inheriting, non-template class constructor

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • l.s.rockfan@web.de

    how to call an inherited, template class constructor from initializerlist of an inheriting, non-template class constructor

    Hello,

    how do i have to call an inherited, templated class constructor from the
    initializer list of the inheriting, non-templated class constructor?

    example code:


    template<typena me T>
    class A
    {
    protected:
    sometype* something;
    T something_else; /*gives the template some sense here*/
    public:
    A(sometype* param) : something(param ) {};
    }


    class B : public A<int>
    {
    public:
    B(sometype* param) : A(param) {}; // <== Compiler Error

    /* further member functions */
    }


    The compiler always tries to identify A as a member variable not being
    found, instead of the base class' constructor.
  • Obnoxious User

    #2
    Re: how to call an inherited, template class constructor frominitializer list of an inheriting, non-template class constructor

    On Fri, 14 Nov 2008 21:28:53 +0100, l.s.rockfan@web .de wrote:
    Hello,
    >
    how do i have to call an inherited, templated class constructor from the
    initializer list of the inheriting, non-templated class constructor?
    >
    example code:
    >
    >
    template<typena me T>
    class A
    {
    protected:
    sometype* something;
    T something_else; /*gives the template some sense here*/
    public:
    A(sometype* param) : something(param ) {};
    }
    >
    >
    class B : public A<int>
    {
    public:
    B(sometype* param) : A(param) {}; // <== Compiler Error
    >
    B(sometype * param) : A<int>(param) {}

    --
    OU
    Remember 18th of June 2008, Democracy died that afternoon.

    Comment

    • l.s.rockfan@web.de

      #3
      Re: how to call an inherited, template class constructor from initializerlist of an inheriting, non-template class constructor

      Obnoxious User wrote:
      On Fri, 14 Nov 2008 21:28:53 +0100, l.s.rockfan@web .de wrote:
      >
      >Hello,
      >>
      >how do i have to call an inherited, templated class constructor from the
      >initializer list of the inheriting, non-templated class constructor?
      >>
      >example code:
      >>
      >>
      >template<typen ame T>
      >class A
      >{
      >protected:
      > sometype* something;
      > T something_else; /*gives the template some sense here*/
      >public:
      > A(sometype* param) : something(param ) {};
      >}
      >>
      >>
      >class B : public A<int>
      >{
      >public:
      > B(sometype* param) : A(param) {}; // <== Compiler Error
      >>
      >
      B(sometype * param) : A<int>(param) {}
      >
      Thanks.

      Mysterious, it really works.

      All the time I tried it before, I coded it outside the class body like

      B::B(sometype* param) : A<int>(param) {}

      and it didn't work because of an ld error.


      When I move it inside the class body (like in my example code above) it
      works.

      Could someone explain this behaviour to me, please?

      Comment

      • l.s.rockfan@web.de

        #4
        Re: how to call an inherited, template class constructor from initializerlist of an inheriting, non-template class constructor

        Obnoxious User wrote:
        On Fri, 14 Nov 2008 21:28:53 +0100, l.s.rockfan@web .de wrote:
        >
        >Hello,
        >>
        >how do i have to call an inherited, templated class constructor from the
        >initializer list of the inheriting, non-templated class constructor?
        >>
        >example code:
        >>
        >>
        >template<typen ame T>
        >class A
        >{
        >protected:
        > sometype* something;
        > T something_else; /*gives the template some sense here*/
        >public:
        > A(sometype* param) : something(param ) {};
        >}
        >>
        >>
        >class B : public A<int>
        >{
        >public:
        > B(sometype* param) : A(param) {}; // <== Compiler Error
        >>
        >
        B(sometype * param) : A<int>(param) {}
        >
        Thanks.

        Mysterious, it really works.

        All the time I tried it before, I coded it outside the class body like

        B::B(sometype* param) : A<int>(param) {}

        and it didn't work because of an ld error: undefined reference to
        A<int>::A(param ).

        But when I move it inside the class body (like in my example code above)
        it works.

        Could someone explain this behaviour to me, please?

        Comment

        Working...