Function Template Specialization with two arguments

Posted on 2004-11-27
Last Modified: 2010-04-24
I have one function template. It takes two arguments. I have used Specialization.

template <class S, class T>
S myfunction(T val)
      S var = 50;
      return var;

int myfunction(int val)
      //S var = 50;
      return 5;

when  I inovke it as
myfunction<int,int>(4); or
It goes in first definition and prints "T".
Why it is not following the function template specialization?
If I run it in Visual studio 6 then it gives correct result. Means follows the function template specialization.
Please try to suggest the appropriate solution.
Question by:mjp_25
    1 Comment
    LVL 48

    Accepted Solution

    I tested in VC++ 6.0 and gets "integer" in both cases. If you get another result with some other compiler, this means, compiler implements template specialization by wrong way.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now