problem on partial specialization of class template

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

    problem on partial specialization of class template

    Dear All,

    Assume I have a class template:

    template<class T, int N = 0>
    class A
    {
    void fun1();
    void fun2();
    void fun3();
    void fun4();

    void NRelatedFun(); // related to template parameter N.
    };

    Here fun1(), fun2(), fun3(), fun4() are the same. NRelatedFun() are
    related to N. How to code the particular functions? I think class
    template can be partial specialized. So I write as

    template<class T, 1>
    void A<T,1>::NRelate dFun();

    But the compilor give some errors. I tried several other ways, but
    still failed.

    I appreicate your kind help.

    Shuisheng

  • Victor Bazarov

    #2
    Re: problem on partial specialization of class template

    shuisheng wrote:
    Assume I have a class template:
    >
    template<class T, int N = 0>
    class A
    {
    void fun1();
    void fun2();
    void fun3();
    void fun4();
    >
    void NRelatedFun(); // related to template parameter N.
    };
    >
    Here fun1(), fun2(), fun3(), fun4() are the same. NRelatedFun() are
    related to N. How to code the particular functions? I think class
    template can be partial specialized. So I write as
    >
    template<class T, 1>
    void A<T,1>::NRelate dFun();
    >
    But the compilor give some errors. I tried several other ways, but
    still failed.
    First of all, what errors does your compiler give you? Please
    start every posting attempt with reading the FAQ. Here, 5.8 is
    applicable.

    Second, you're specialising a member without specialising the class.
    It could be the problem. Why are you declaring a member of your
    A<T,1as a function when the template specialisation can have it
    as a static data member? YOu need to specialise the class first,
    then show that 'NRelatedFun' is indeed a function with the specific
    signature, then you can define it.

    Anyway, read the FAQ 5.8.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    • shuisheng

      #3
      Re: problem on partial specialization of class template


      Victor Bazarov 写道:
      shuisheng wrote:
      Assume I have a class template:

      template<class T, int N = 0>
      class A
      {
      void fun1();
      void fun2();
      void fun3();
      void fun4();

      void NRelatedFun(); // related to template parameter N.
      };

      Here fun1(), fun2(), fun3(), fun4() are the same. NRelatedFun() are
      related to N. How to code the particular functions? I think class
      template can be partial specialized. So I write as

      template<class T, 1>
      void A<T,1>::NRelate dFun();

      But the compilor give some errors. I tried several other ways, but
      still failed.
      >
      First of all, what errors does your compiler give you? Please
      start every posting attempt with reading the FAQ. Here, 5.8 is
      applicable.
      I got your message. I have read it and will follow it.
      >
      Second, you're specialising a member without specialising the class.
      It could be the problem. Why are you declaring a member of your
      A<T,1as a function when the template specialisation can have it
      as a static data member? YOu need to specialise the class first,
      then show that 'NRelatedFun' is indeed a function with the specific
      signature, then you can define it.
      Thanks!.

      Shuisheng

      Comment

      Working...