Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6609769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:45:25+00:00 2026-05-25T19:45:25+00:00

Consider the following: template <typename T> class testString { public: typedef T* iterator; void

  • 0

Consider the following:

template <typename T>
class testString
{
public:

  typedef T* iterator;

  void insert(iterator aPos, size_t numChars, T aChar);
  testString<T>& insert(size_t aIndex, size_t numChars, T aChar);
};

template <typename T>
void testString<T>::insert( iterator aPos, size_t numChars, T aChar )
{

}

template <typename T>
testString<T>& testString<T>::insert( size_t aIndex, size_t numChars, T aChar )
{
  return *this;
}

int main()
{
  testString<char> c;
  c.insert(0, 10, 'a'); // ambiguous call
  c.insert(1, 10, 'a'); // compiles fine

  return 0;
}

Why am I getting an ambiguous call? Initially, I had a guess (because it is 0, it can be anything), but then I looked at std::string. I looked at the source, and these are the two functions:

void               insert ( iterator p, size_t n, char c );
string&            insert ( size_t pos1, size_t n, char c );

And I tried the same calls with std::string, and it works fine. Now I have no clue why 0 works with std::string and is immediately recognized as a size_t while in my implementation it is not (another guess was type traits, but there is no evidence of it in the source)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:45:25+00:00Added an answer on May 25, 2026 at 7:45 pm

    Ah, one of those times when you’re like “wouldn’t it be better if in c++, 0 was not the same as null?”

    Anyway, your iterator type is typedef’d to T*, which is char*, and 0 is a fine value for a char*, hence the ambiguity (er, as K-ballo wrote). In std::string, the iterator type won’t be a char*, it’ll be something fancy like another (templatized) class…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following example: template <typename T> class A { public: void f() {
Consider the following use of template template parameters... #include <iostream> template <typename X> class
Consider the following code: #include <stdio.h> namespace Foo { template <typename T> void foo(T
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider the following function template: template<typename T> void Foo(T) { // ... } Pass-by-value
Consider the following program: template <typename T> struct t { struct base { void
Consider the following template class class MyClassInterface { public: virtual double foo(double) = 0;
consider the following program: namespace NS2 { class base { }; template<typename T> int
Consider the following code template<typename T, int N> struct A { typedef T value_type;
Consider the following code: template <typename T> class B { }; template <typename T>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.