Tom Tom - 1 year ago 107
C++ Question

How initialize std::set<std::wstring> *wordDict

I have the following line of code:

std::set<std::wstring> *wordDict = std::unordered_set<std::wstring>();

I got following compile error:

..\Test.cpp:206:71: error: cannot convert 'std::unordered_set<std::__cxx11::basic_string<wchar_t> >' to 'std::set<std::__cxx11::basic_string<wchar_t> >*' in initialization
std::set<std::wstring> *wordDict = std::unordered_set<std::wstring>();

How to fix it ?

Answer Source


std::set<std::wstring> wordDict;


std::unordered_set<std::wstring> wordDict;

depending on what kind of set it it is you actually want.

If you really need dynamic allocation, which is very unlikely because you almost never need to dynamically allocate a standard container:

auto wordDict = new std::set<std::wstring>;


auto wordDict = new std::unordered_set<std::wstring>;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download