Jump to content
  • Advertisement
Sign in to follow this  
littlekid

Explicit Template Specialization - Linker Error

This topic is 2806 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

Hi suppose I have the code as follow


//apple.header
class Apple
{
public:
template <typename ty> void Cut(ty&& var);
};

//apple.cpp
template<typename ty> void Apple::Cut(ty&& var)
{
DoSomethingGreat(std::forward<ty>(var));
}

template void Apple::Cut<MyData&&>(MyData&& var); //specialization 1
template void Apple::Cut<const MyData&>(const MyData& var); //specialization 2

//main.cpp
int main()
{
MyData data;

Apple test_apple;

test_apple.Cut(data); //linker error
}


why does this generate a linker error? It says it can't link to "void Apple::Cut(MyData& var)". If I provide the said specialization it works.

However I don't understand why doesn't it call specialization 2 instead? since MyData& can be bound and converted to const MyData&

regards

Share this post


Link to post
Share on other sites
Advertisement
Overload resolution is compile time. Finding a template instantiation is link time. What happens during link time has no effect on what happens at compile time.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!