|
-
July 17th, 2017, 05:24 AM
#5
Re: template function in non-template class
 Originally Posted by JohnnyTest
But now it gives different errors. It wants to use template function when string argument is passed. But I have already overloaded the function with separate string argument, so why doesn't it use that?
Recall that there is the concept of a null terminated string as inherited from C (i.e., contiguous sequences of char, stored in arrays, terminated by a null character), and then there are string objects with the type of std::string. It looks like the compiler chose the template because the type of the argument was that of a char array rather than a std::string. There may be other solutions, but perhaps one quick solution would be to overload for const char*. This overload can delegate to the constructor that overloads for std::string const reference, e.g., by explicitly constructing a std::string object as the argument as it delegates, so you don't really do extra work.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|