-3

Update: This is a wrong question. There is no non-const version of string::data(); ignore this question. I'm sorry!

string::data has a const version and a non-const version. In my following code, str is obviously a non-const object, so str.data() should call the non-const version. However, VC++ 2013 doesn't think so.

#include <string>

using namespace std;

void f1(char* sz)
{}

template<class stringT>
void f2(stringT& str)
{
    f1(str.data());
}

int main()
{
    string s;

    f2(s);
    // error C2664: 'void f1(char *)' : 
    // cannot convert argument 1 from 'const char *' to 'char *'
}
xmllmx
  • 39,765
  • 26
  • 162
  • 323

1 Answers1

3

string::data has a const version and a non-const version.

No, it doesn't. There is only a const version.

jwodder
  • 54,758
  • 12
  • 108
  • 124