visual-c++

Inserting to std::unordered_map calls hash function twice in MSVC++'s STL, bad design or special reason?

人盡茶涼 提交于 2020-08-27 02:23:12
问题 For this code: #include<unordered_map> #include<iostream> using namespace std; struct myhash { unsigned operator()(const unsigned&v)const { cout<<"Hash function is called:"<<v<<endl; return v; } }; unordered_map<unsigned,unsigned,myhash>mp; int main() { for (unsigned i=0;i<3;++i) { cout<<"Visiting hash table:"<<i<<endl; ++mp[i]; } } When using g++, there's no surprise with the output: Visiting hash table:0 Hash function is called:0 Visiting hash table:1 Hash function is called:1 Visiting hash

Visual C Runtime functions unresolved with `/MT`

社会主义新天地 提交于 2020-08-25 06:42:22
问题 I'm converting a large Visual Studio solution from VS 2010 to VS 2017. One of the projects in the solution contains only C, no C++, and compiles with /MT to link statically with the multi-threaded C runtime. Unfortunately, the C runtime functions don't seem to be getting found by the linker, even though libcmt.lib is in the list of libraries. The linker actually says that this lib is unused in the verbose output. Why is the linker not finding the functions? Output: redacted.obj : error

Forward declarations in C++ modules (MSVC)

独自空忆成欢 提交于 2020-08-22 15:12:22
问题 I have been experimenting with modules implementation as provided by the MSVC lately and I've run into an interesting scenario. I have two classes that have a mutual dependency in their interfaces, which means that I'll have to use forward declarations to get it to compile. The following code shows an example: Module interface export module FooBar; export namespace FooBar { class Bar; class Foo { public: Bar createBar(); }; class Bar { public: Foo createFoo(); }; } Module implementation