John
John

Reputation: 16007

Is this equivalent to a std::string?

Trying to track down a LNK2019 Unresolved External Symbol error on a function that has a number of std::string const & arguments.

Step one of this answer says to check decorated / undecorated names, and this is what I'm seeing in the linker error text in the argument list:

class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &

Is this also std::string const & ?

Thanks for your help.

I'm running VS 2008.

Upvotes: 1

Views: 274

Answers (1)

MSalters
MSalters

Reputation: 180303

Yes.

As part of the C++ standardization, the std::string class was made more STL-compatible. Like the STL containers, the element type can be chosen. Common choices are char and wchar_t, but Visual C++ users can also use TCHAR. Like STL containers, memory allocation is handled by an allocator.

However, strings are unlike other containers because some methods need to perform more complex operations on their elements. std::set<T> only needs to compare two T objects, but std::string needs to deal with multi-byte encodings and such complications. These details are wrapped up in class std::char_traits<char>.

So, with all this complexity, you end up with std::basic_string<char, std::char_traits<char>, std::allocator<char> >. That's of course not very friendly, and most people just need the defaults. std::string is the friendly name for that.

Upvotes: 4

Related Questions