Jump to content
  • Advertisement
Sign in to follow this  
CuppoJava

Having problems compiling when using template specialization

This topic is 4784 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, i'm just doing a small excercise and I couldn't get the following code to pass the compiler, can someone point out what I'm doing wrong? Here's my template function:
template<typename T>
T maxn(const T* array, unsigned n)
and here's the specialized function:
template<> char* maxn<char*>(const char** str, unsigned n)
but the compiler says error C2912: explicit specialization; 'char *maxn<char*>(const char ** ,unsigned int)' is not a specialization of a function template Thanks for your help. -Cuppo. PS: Also can I have some help on this syntax?
void print(char** arrayOfStrings)
void print((char[])* arrayOfStrings)
void print(char* arrayOfStrings[])
Do these all mean the same thing? Is there a preferred idiom? Thanks a lot.

Share this post


Link to post
Share on other sites
Advertisement
I think the problem is that though const T is the same as T const (a constant of type T), const char* (a pointer to a const char) is NOT the same as char * const (a const pointer to a char).
Since const T where T is char* is equal to char* const, I think it should work if you try it like this:

template<typename T>
T maxn(const T* array, unsigned n);

template<> char* maxn<char*>(char* const * str, unsigned n);

(though I haven't tried it in a compiler and template specialization syntax is something I usually have to look up [wink])

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!