overloading non-template member functions with template member functions

Discussion in 'C++' started by Hicham Mouline, Apr 23, 2009.

  1. Hello,

    I have this code
    http://codepad.org/CDOFhSqZ

    I have a non templated member function GetSpot(tType) const
    and a templated one.

    Besides, argument 2 and 3 of the templated have default arguments.

    Users of this class call either

    class.GetSpot( 10. );

    or

    class.GetSpot<Linear, Polynomial>( 15. ); // case 2

    or

    class.GetSpot<Linear, Linear>( 15., Linear(5), Linear(7) );

    These actual calls happen in 1 translation unit and so the member functions
    are instantiated.

    Question 1 : Is this valid C++03?
    Question 2 : I would like opinions about the style
    Question 3 : with vs2005 debugger, arg2 and arg3 in case 2 are not
    constructed properly sometimes.

    Question 4: would removing the non templated member, and setting default
    template args for Interp and Extrap
    be possible with at the same time having default formal args 2 and 3.
    Would this then be a better style?

    PS: typename boost::call_traits<Interp>::param_type is simply
    const Interp&
    in this case

    regards,
     
    Hicham Mouline, Apr 23, 2009
    #1
    1. Advertising

  2. Re: overloading non-template member functions with template memberfunctions

    Hicham Mouline wrote:
    > Hello,
    >
    > I have this code
    > http://codepad.org/CDOFhSqZ
    >
    > I have a non templated member function GetSpot(tType) const
    > and a templated one.
    >
    > Besides, argument 2 and 3 of the templated have default arguments.
    >
    > Users of this class call either
    >
    > class.GetSpot( 10. );


    class is a reserved word. I assume this is a variable of type
    SpotCurve1D<Curve>.


    >
    > or
    >
    > class.GetSpot<Linear, Polynomial>( 15. ); // case 2
    >
    > or
    >
    > class.GetSpot<Linear, Linear>( 15., Linear(5), Linear(7) );
    >
    > These actual calls happen in 1 translation unit and so the member functions
    > are instantiated.
    >
    > Question 1 : Is this valid C++03?


    I suppose this is not actual code, SpotCurve1D would have only private
    members and mContainerSize is not present.

    The best solution is activating proper flags on your compiler to check
    for conformance.

    > Question 2 : I would like opinions about the style


    * What do fType and tType stand for ?
    * What's the point of boost::call_traits<Interp>::param_type in this case ?
    * use tType() or tType(0) instead of static_cast<tType>(0)
    * Your comments are not consistent (use \ or @ but not both).

    > Question 3 : with vs2005 debugger, arg2 and arg3 in case 2 are not
    > constructed properly sometimes.


    Track construction/destruction to check but I don't see the problem in
    your code.

    > Question 4: would removing the non templated member, and setting default
    > template args for Interp and Extrap
    > be possible with at the same time having default formal args 2 and 3.

    Yes, use const Interp& instead of boost.

    > Would this then be a better style?


    Everything that make the code clearer is beeter style.


    >
    > PS: typename boost::call_traits<Interp>::param_type is simply
    > const Interp&
    > in this case



    --
    Michael
     
    Michael DOUBEZ, Apr 24, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xiangliang Meng
    Replies:
    1
    Views:
    1,631
    Victor Bazarov
    Jun 21, 2004
  2. BigMan
    Replies:
    3
    Views:
    1,447
    BigMan
    Apr 22, 2005
  3. ghager
    Replies:
    6
    Views:
    629
    ghager
    Jan 19, 2006
  4. flounder
    Replies:
    4
    Views:
    518
    flounder
    Apr 2, 2009
  5. Hicham Mouline
    Replies:
    0
    Views:
    441
    Hicham Mouline
    Apr 23, 2009
Loading...

Share This Page