0

I'm using emplace_back function in a cpp project in visual studio and it works correctly. Visual studio shows following definition for it:

void std::vector<std::string>::emplace_back<CHAR(&)[1]>(CHAR(&_Val)[1])

Then, I'm going to move my cpp project files to a MFC project and use them in a dialog based app. When I moved codes to MFC project, emplace_back definition has changed to:

void std::vector<std::string>::emplace_back<WCHAR(&)[1]>(WCHAR(&_Val)[1])

And it leads to C2664 Error in xmemory0 after build:

Error   C2664
std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(const std::basic_string<char, std::char_traits<char>, std::allocator<char>> &)':
cannot convert argument 1 from 'WCHAR [1]' to 'std::initializer_list<_Elem>'

And in output it says:

note: see reference to function template instantiation 'void std::vector<std::string,std::allocator<_Ty>>::emplace_back<WCHAR(&)[1]>(WCHAR (&)[1])' being compiled
1>          with
1>          [
1>              _Ty=std::string
1>          ]

How can I deal with such problems? Is there any option in properties of Visual Studio Project to correct?

Thanks

Mahdi
  • 664
  • 3
  • 15
  • 35
  • It's about 'Character set', https://stackoverflow.com/a/26073905/853569 – Maadiah Jan 02 '18 at 03:11
  • 1
    How you're using it is very relevant to the question. The error looks like the instantiation you used changed, not the definition. – chris Jan 02 '18 at 03:43
  • There is a vector of strings and you are trying to add a single wide char to this vector? Explain what you are trying to accomplish and what code you are using. Also have a look at `std::wstring` for Unicode string, or `vector` for vector of Unicode strings. – Barmak Shemirani Jan 02 '18 at 05:15
  • Please edit the question to show the code where you call `std::vector::emplace_back()` that is causing the problem. I suppose the argument for `emplace_back()` is `TCHAR` based. In the project where it worked you propably build for ANSI character set (`TCHAR` is typedef for `char`), in the new project you propably have Unicode enabled (`TCHAR` is typedef for `wchar_t`). – zett42 Jan 02 '18 at 08:21

0 Answers0