template member function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexander Stippler

    template member function

    Hey all,

    what exactly is forbidden/wrong with the following call of a template
    member function;

    template <typename T>
    struct Base
    {
    template <int N>
    void
    cio();
    };

    template <typename T>
    struct Derived
    : public Base<T>
    {
    template <int N>
    void
    cio()
    {
    Base<T>::cio<N> (); // !!!!!! <--- what's the
    problem here?
    }
    };

    int
    main()
    {
    }

    Best regards,
    Alex

  • Sam

    #2
    Re: template member function

    Alexander Stippler writes:
    Hey all,
    >
    what exactly is forbidden/wrong with the following call of a template
    member function;
    >
    template <typename T>
    struct Base
    {
    template <int N>
    void
    cio();
    };
    >
    template <typename T>
    struct Derived
    : public Base<T>
    {
    template <int N>
    void
    cio()
    {
    Base<T>::cio<N> (); // !!!!!! <--- what's the
    problem here?
    }
    };
    >
    int
    main()
    {
    }
    Sometimes the parsing rules, when templates are involved, get a bit hairy
    and what might seem obvious to a meatbag, is not so obvious to a mechanical
    parser, to you have to give the compiler a bit of help. Rewriting the
    offending statement as:

    Base<T*b=static _cast<Base<T*>( this);

    b->cio<N>();

    This should do what you want.


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.7 (GNU/Linux)

    iD8DBQBH1CICx9p 3GYHlUOIRAuKiAJ 9O2CngmUz5CywT0 9XVKNUpqchGvQCf XOuM
    3uV5MPry+XjrQfJ e5t7mAFU=
    =9V16
    -----END PGP SIGNATURE-----

    Comment

    • witmer

      #3
      Re: template member function

      On Mar 9, 12:27 pm, Alexander Stippler <alexander.stip p...@uni-ulm.de>
      wrote:
      Hey all,
      >
      what exactly is forbidden/wrong with the following call of a template
      member function;
      >
      template <typename T>
      struct Base
      {
          template <int N>
              void
              cio();
      >
      };
      >
      template <typename T>
      struct Derived
          : public Base<T>
      {
          template <int N>
              void
              cio()
              {
                  Base<T>::cio<N> ();           // !!!!!!  <---   what's the
      problem here?
              }
      >
      };
      >
      int
      main()
      {
      >
      }
      The parser doesn't know that cio is a template.
      Try:

      Base<T>::templa te cio<N>();

      Comment

      • Alexander Stippler

        #4
        Re: template member function

        On 2008-03-09 18:44:34 +0100, Sam <sam@email-scan.comsaid:
        This is a MIME GnuPG-signed message. If you see this text, it means that
        your E-mail or Usenet software does not support MIME signed messages.
        The Internet standard for MIME PGP messages, RFC 2015, was published in 1996.
        To open this message correctly you will need to install E-mail or Usenet
        software that supports modern Internet standards.
        >
        --=_mimegpg-commodore.email-scan.com-29220-1205084674-0001
        Content-Type: text/plain; format=flowed; charset="US-ASCII"
        Content-Disposition: inline
        Content-Transfer-Encoding: 7bit
        >
        Alexander Stippler writes:
        >
        >Hey all,
        >>
        >what exactly is forbidden/wrong with the following call of a template
        >member function;
        >>
        >template <typename T>
        >struct Base
        >{
        >template <int N>
        >void
        >cio();
        >};
        >>
        >template <typename T>
        >struct Derived
        >: public Base<T>
        >{
        >template <int N>
        >void
        >cio()
        >{
        >Base<T>::cio<N >(); // !!!!!! <--- what's the
        >problem here?
        >}
        >};
        >>
        >int
        >main()
        >{
        >}
        >
        Sometimes the parsing rules, when templates are involved, get a bit hairy
        and what might seem obvious to a meatbag, is not so obvious to a mechanical
        parser, to you have to give the compiler a bit of help. Rewriting the
        offending statement as:
        >
        Base<T*b=static _cast<Base<T*>( this);
        >
        b->cio<N>();
        >
        This should do what you want.
        >
        >
        --=_mimegpg-commodore.email-scan.com-29220-1205084674-0001
        Content-Type: application/pgp-signature
        Content-Transfer-Encoding: 7bit
        >
        -----BEGIN PGP SIGNATURE-----
        Version: GnuPG v1.4.7 (GNU/Linux)
        >
        iD8DBQBH1CICx9p 3GYHlUOIRAuKiAJ 9O2CngmUz5CywT0 9XVKNUpqchGvQCf XOuM
        3uV5MPry+XjrQfJ e5t7mAFU=
        =9V16
        -----END PGP SIGNATURE-----
        >
        --=_mimegpg-commodore.email-scan.com-29220-1205084674-0001--
        Thanks a lot. It should have been obvious to me. I even knew your
        solution long time ago :-(

        Comment

        Working...