template specialization in member function

Discussion in 'C++' started by John, Jan 23, 2005.

  1. John

    John Guest

    I have a class

    class x{

    public:

    template<typename X>
    friend X func(X a){
    ....
    }

    // I would also want to write the following

    template< >
    friend double func<double>(double a){
    ....
    }


    }


    Can someone help on what i am doing wrong?

    Thanks,
    --j
     
    John, Jan 23, 2005
    #1
    1. Advertising

  2. John wrote:
    > I have a class
    >
    > class x{
    >
    > public:
    >
    > template<typename X>
    > friend X func(X a){
    > ...
    > }


    Post a compilable code here to clarify
    your question.

    >
    > // I would also want to write the following
    >
    > template< >
    > friend double func<double>(double a){


    'friend' appears in the declaration of a function,
    and not in the definition of the function.

    Also this friend function does not seems to take
    any user-defined data types. It just takes a 'double'.
    'friend' functions are used to access *all the members*
    of a given class.

    While there is nothing wrong with this as far as the
    grammar of the language is concerned, you may need
    to revisit this anyway, if this is what you intend to
    write.

    > ...
    > }
    >
    >
    > }
    >
    >
    > Can someone help on what i am doing wrong?


    Post code.

    --
    Karthik.
     
    Karthik Kumar, Jan 23, 2005
    #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. Dave
    Replies:
    4
    Views:
    7,775
    pdixtl
    Jun 4, 2010
  2. Ruben Campos
    Replies:
    3
    Views:
    6,533
  3. BigMan
    Replies:
    1
    Views:
    539
  4. Joseph Turian
    Replies:
    4
    Views:
    622
    John Carson
    Mar 20, 2006
  5. toton
    Replies:
    2
    Views:
    360
    toton
    Feb 22, 2008
Loading...

Share This Page