Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Shannon Barber

Member Template Specialization

This topic is 6098 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is Member Template Specialization part of the C++ spec? I swear I just read in "Modern C++ Desing" that it isn''t - but MSVC will actually let you specialize member function templates! I can''t imagine the MS compiler having such an extention when they lack other template features.

Share this post


Link to post
Share on other sites
Advertisement
Where did u read that? I though it was VC++ that doesn't allow member function specializations!

The below compiles fine on gcc, comeau but fails with VC++. What do u think?

    
#include <iostream>

using namespace std;

template <typename T>
class C
{
public:
template <typename X>
void Method( X x)
{
cout << "Generic called" << endl;
}
};

template <>
template<> void C<int>::Method<float>( float x )
{
cout << "Specialization called" << endl;
}


int main()
{
C<int> obj;

obj.Method( 1.2f ); // calls specialized

obj.Method( 1 ); // calls generic


return 0;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!