Der folgende Code kompiliert nicht: < /p>
Code: Select all
//Test.ixx
export module Test;
export import std;
export template
struct Foo {
size_t hash = 0;
};
namespace std {
template
struct hash {
using F = int;
size_t operator()(const Foo& f) const noexcept {
return hash{}(f.hash);
}
};
}
//main.cpp
import Test;
int main() {
std::unordered_map map; //multiple compiler errors
}
< /code>
Mit dem obigen Code erhalte ich die folgenden Compiler -Fehler: < /p>
std::_Hash::_Alnode: cannot access protected typedef declared in class std::_Hash` (unordered map, line 72)
see declaration of 'std::_Hash::_Alnode'
with
[
_Kty=Foo,
_Ty=std::string,
_Hasher=std::hash,
_Keyeq=std::equal_to,
_Alloc=std::allocator
] (xhash 330)
see declaration of 'std::_Hash'
with
[
_Kty=Foo,
_Ty=std::string,
_Hasher=std::hash,
_Keyeq=std::equal_to,
_Alloc=std::allocator
] (xhash 327)
see reference to class template instantiation 'std::unordered_map' being compiled (main.cpp 6)
Code: Select all
import Test;
int main()
{
std::hash::F; //new line
std::unordered_map map;
}