Typename or class?

Discussion in 'C++' started by nietoperz34, May 26, 2012.

  1. nietoperz34

    nietoperz34 Guest

    Welcome. What better use in templates C++? Typename or class?
    Better yes:
    template <class T1, class T2>
    T1 function(T2 argument);
    Or better yes:
    template <typename T1, typename T2>
    T1 function(T2 argument);
     
    nietoperz34, May 26, 2012
    #1
    1. Advertising

  2. Jorgen Grahn <> wrote:
    > On Sat, 2012-05-26, nietoperz34 wrote:
    >> Welcome. What better use in templates C++? Typename or class?
    >> Better yes:
    >> template <class T1, class T2>
    >> T1 function(T2 argument);
    >> Or better yes:
    >> template <typename T1, typename T2>
    >> T1 function(T2 argument);

    >
    > I didn't know #2 was valid, so I have to say #1.


    You didn't know that #2 is valid, so you have to say #1? What sense does
    that make?
     
    Juha Nieminen, May 26, 2012
    #2
    1. Advertising

  3. nietoperz34

    Jorgen Grahn Guest

    On Sat, 2012-05-26, Juha Nieminen wrote:
    > Jorgen Grahn <> wrote:
    >> On Sat, 2012-05-26, nietoperz34 wrote:
    >>> Welcome. What better use in templates C++? Typename or class?
    >>> Better yes:
    >>> template <class T1, class T2>
    >>> T1 function(T2 argument);
    >>> Or better yes:
    >>> template <typename T1, typename T2>
    >>> T1 function(T2 argument);

    >>
    >> I didn't know #2 was valid, so I have to say #1.

    >
    > You didn't know that #2 is valid, so you have to say #1? What sense does
    > that make?


    Do I really have to spell it out?

    Ok: I have frequently seen #1, but never or rarely #2. So I assume #1
    is the most common form, and thus the preferable one.

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
     
    Jorgen Grahn, May 26, 2012
    #3
  4. nietoperz34

    Pavel Guest

    Leigh Johnston wrote:
    > On 26/05/2012 21:12, Paul <pchrist wrote:
    >> "nietoperz34"<> wrote in message
    >> news:...
    >>> Welcome. What better use in templates C++? Typename or class?
    >>> Better yes:
    >>> template<class T1, class T2>
    >>> T1 function(T2 argument);
    >>> Or better yes:
    >>> template<typename T1, typename T2>
    >>> T1 function(T2 argument);

    >>
    >> Use class when a class type is expected, otherwise use typename.

    >
    > Who says? You?

    Count me in, too. Talleyrand once said that speech was given to man to disguise
    his thoughts; this may be true for diplomats but I think programming languages
    were given to engineers to honestly express their intentions (whether or not the
    compilers enforce the implied contracts).

    >
    > /Leigh
    >


    -Pavel
     
    Pavel, May 27, 2012
    #4
    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. Alexander Malkis

    class vs. typename

    Alexander Malkis, Apr 6, 2004, in forum: C++
    Replies:
    7
    Views:
    13,133
    psubramani
    Oct 20, 2012
  2. Replies:
    6
    Views:
    630
    Victor Bazarov
    Oct 20, 2005
  3. Victor Bazarov
    Replies:
    6
    Views:
    319
  4. Kobe
    Replies:
    9
    Views:
    473
    Howard
    Feb 17, 2006
  5. Jakob Bieling

    Q: typename or not typename?

    Jakob Bieling, Mar 14, 2006, in forum: C++
    Replies:
    2
    Views:
    363
    Rolf Magnus
    Mar 14, 2006
Loading...

Share This Page