Create an unordered_map with custom object as keyHash Object problem in C++Is there any advantage of using map over unordered_map in case of trivial keys?Using an object reference as a key in std::unordered_mapUsing std::pair as key in std::unordered_mapC++ unordered_map using a custom class type as the keyWhen should we provide our own Hash function for `std::unordered_set`Why should I use a pointer rather than the object itself?Unordered Map with three unsigned chars as keyReturn type mismatch for operator implementation in unordered_map wrapperC++ - type qualifiers error when hashing user defined object

Python 3 - simple temperature program version 1.3

What is monoid homomorphism exactly?

Where to draw the line between quantum mechanics theory and its interpretation(s)?

Can you figure out this language?

How can I finally understand the confusing modal verb "мочь"?

Why increasing of the temperature of the objects like wood, paper etc. doesn't fire them?

Huffman Code in C++

What word describes the sound of an instrument based on the shape of the waveform of its sound?

All of my Firefox add-ons been disabled suddenly, how can I re-enable them?

Copper as an adjective to refer to something made of copper

How is trade in services conducted under the WTO in the absence of the Doha conclusion?

What is the meaning of 「隣のおじいさんは言いました」

Changing stroke width vertically but not horizontally in Inkscape

Can anyone identify this unknown 1988 PC card from The Palantir Corporation?

Problem with estimating a sequence with intuition

Why can't argument be forwarded inside lambda without mutable?

Is there precedent or are there procedures for a US president refusing to concede to an electoral defeat?

What detail can Hubble see on Mars?

What does the phrase "go for the pin" mean here?

Where did Lovecraft write about Carcosa?

What are the requirements for a river delta to form?

Gerrymandering Puzzle - Rig the Election

Is crescere the correct word meaning to to grow or cultivate?

How to preserve a rare version of a book?



Create an unordered_map with custom object as key


Hash Object problem in C++Is there any advantage of using map over unordered_map in case of trivial keys?Using an object reference as a key in std::unordered_mapUsing std::pair as key in std::unordered_mapC++ unordered_map using a custom class type as the keyWhen should we provide our own Hash function for `std::unordered_set`Why should I use a pointer rather than the object itself?Unordered Map with three unsigned chars as keyReturn type mismatch for operator implementation in unordered_map wrapperC++ - type qualifiers error when hashing user defined object






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I want to create an std::unordered_map with Node as the key. I have already overloaded the operator == and <. I have also defined a hash function. However, it is giving me error:



C2280: std::hash<_Kty>::hash(const std::hash<_Kty> &): attempting to reference a deleted function



Here is my code for the Node class:



#include "Node.h"

Node::Node()
word = Word();


Node::Node(Word input_word) : word(input_word)

Node::Node(const Node& other)
word = other.word;
connection = other.connection;


Node::~Node()


bool Node::operator<(const Node& other)
return (word < other.get_word());


bool Node::operator==(const Node& other)
if (word == other.word)
if (connection.size() == other.connection.size())
for (unsigned int i = 0; i < connection.size(); i++)
if (connection[i] != other.connection[i])
return false;


return true;
else
return false;

else
return false;



Word Node::get_word() const
return word;


int Node::add_connection(Edge* input_node)
connection.push_back(input_node);
return SUCCESS;


vector<Edge*> Node::retrieve_connection() const
return connection;



namespace std
template <> struct hash<Node>
size_t operator()(const Node& other) const
return hash<string>()(other.get_word().get_string()) ^
hash<int>()(other.retrieve_connection().size());

;



I am very confused about what I should add next. I have tried most suggestions that I can find on websites, but none of them works.



Thank you for your attention!










share|improve this question



















  • 3





    Please post a Minimal, Complete, and Verifiable example and the complete error messages from the compiler.

    – R Sahu
    Mar 23 at 4:39






  • 1





    "I have tried most suggestions that I can find on websites, but none of them works." It's hard for us to help you when we can't try suggestions, get error messages with our preferred compiler, simplify the code to see if the error goes away, and so on.

    – David Schwartz
    Mar 23 at 5:20











  • I had to make a lot of assumptions about your Node and Word classes (many of them bad coding style; e.g. you should use = default for constructors and destructors when possible, or in this case just use the Rule of Zero and don't explicitly define them at all), but when I did everything compiled perfectly. Please share the full error message and see if you can provide a complete (non-)working minimal example.

    – Daniel H
    Mar 23 at 5:21

















0















I want to create an std::unordered_map with Node as the key. I have already overloaded the operator == and <. I have also defined a hash function. However, it is giving me error:



C2280: std::hash<_Kty>::hash(const std::hash<_Kty> &): attempting to reference a deleted function



Here is my code for the Node class:



#include "Node.h"

Node::Node()
word = Word();


Node::Node(Word input_word) : word(input_word)

Node::Node(const Node& other)
word = other.word;
connection = other.connection;


Node::~Node()


bool Node::operator<(const Node& other)
return (word < other.get_word());


bool Node::operator==(const Node& other)
if (word == other.word)
if (connection.size() == other.connection.size())
for (unsigned int i = 0; i < connection.size(); i++)
if (connection[i] != other.connection[i])
return false;


return true;
else
return false;

else
return false;



Word Node::get_word() const
return word;


int Node::add_connection(Edge* input_node)
connection.push_back(input_node);
return SUCCESS;


vector<Edge*> Node::retrieve_connection() const
return connection;



namespace std
template <> struct hash<Node>
size_t operator()(const Node& other) const
return hash<string>()(other.get_word().get_string()) ^
hash<int>()(other.retrieve_connection().size());

;



I am very confused about what I should add next. I have tried most suggestions that I can find on websites, but none of them works.



Thank you for your attention!










share|improve this question



















  • 3





    Please post a Minimal, Complete, and Verifiable example and the complete error messages from the compiler.

    – R Sahu
    Mar 23 at 4:39






  • 1





    "I have tried most suggestions that I can find on websites, but none of them works." It's hard for us to help you when we can't try suggestions, get error messages with our preferred compiler, simplify the code to see if the error goes away, and so on.

    – David Schwartz
    Mar 23 at 5:20











  • I had to make a lot of assumptions about your Node and Word classes (many of them bad coding style; e.g. you should use = default for constructors and destructors when possible, or in this case just use the Rule of Zero and don't explicitly define them at all), but when I did everything compiled perfectly. Please share the full error message and see if you can provide a complete (non-)working minimal example.

    – Daniel H
    Mar 23 at 5:21













0












0








0








I want to create an std::unordered_map with Node as the key. I have already overloaded the operator == and <. I have also defined a hash function. However, it is giving me error:



C2280: std::hash<_Kty>::hash(const std::hash<_Kty> &): attempting to reference a deleted function



Here is my code for the Node class:



#include "Node.h"

Node::Node()
word = Word();


Node::Node(Word input_word) : word(input_word)

Node::Node(const Node& other)
word = other.word;
connection = other.connection;


Node::~Node()


bool Node::operator<(const Node& other)
return (word < other.get_word());


bool Node::operator==(const Node& other)
if (word == other.word)
if (connection.size() == other.connection.size())
for (unsigned int i = 0; i < connection.size(); i++)
if (connection[i] != other.connection[i])
return false;


return true;
else
return false;

else
return false;



Word Node::get_word() const
return word;


int Node::add_connection(Edge* input_node)
connection.push_back(input_node);
return SUCCESS;


vector<Edge*> Node::retrieve_connection() const
return connection;



namespace std
template <> struct hash<Node>
size_t operator()(const Node& other) const
return hash<string>()(other.get_word().get_string()) ^
hash<int>()(other.retrieve_connection().size());

;



I am very confused about what I should add next. I have tried most suggestions that I can find on websites, but none of them works.



Thank you for your attention!










share|improve this question
















I want to create an std::unordered_map with Node as the key. I have already overloaded the operator == and <. I have also defined a hash function. However, it is giving me error:



C2280: std::hash<_Kty>::hash(const std::hash<_Kty> &): attempting to reference a deleted function



Here is my code for the Node class:



#include "Node.h"

Node::Node()
word = Word();


Node::Node(Word input_word) : word(input_word)

Node::Node(const Node& other)
word = other.word;
connection = other.connection;


Node::~Node()


bool Node::operator<(const Node& other)
return (word < other.get_word());


bool Node::operator==(const Node& other)
if (word == other.word)
if (connection.size() == other.connection.size())
for (unsigned int i = 0; i < connection.size(); i++)
if (connection[i] != other.connection[i])
return false;


return true;
else
return false;

else
return false;



Word Node::get_word() const
return word;


int Node::add_connection(Edge* input_node)
connection.push_back(input_node);
return SUCCESS;


vector<Edge*> Node::retrieve_connection() const
return connection;



namespace std
template <> struct hash<Node>
size_t operator()(const Node& other) const
return hash<string>()(other.get_word().get_string()) ^
hash<int>()(other.retrieve_connection().size());

;



I am very confused about what I should add next. I have tried most suggestions that I can find on websites, but none of them works.



Thank you for your attention!







c++ hash unordered-map






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 5:14









melpomene

63.7k55195




63.7k55195










asked Mar 23 at 4:21









Runsheng MaRunsheng Ma

13




13







  • 3





    Please post a Minimal, Complete, and Verifiable example and the complete error messages from the compiler.

    – R Sahu
    Mar 23 at 4:39






  • 1





    "I have tried most suggestions that I can find on websites, but none of them works." It's hard for us to help you when we can't try suggestions, get error messages with our preferred compiler, simplify the code to see if the error goes away, and so on.

    – David Schwartz
    Mar 23 at 5:20











  • I had to make a lot of assumptions about your Node and Word classes (many of them bad coding style; e.g. you should use = default for constructors and destructors when possible, or in this case just use the Rule of Zero and don't explicitly define them at all), but when I did everything compiled perfectly. Please share the full error message and see if you can provide a complete (non-)working minimal example.

    – Daniel H
    Mar 23 at 5:21












  • 3





    Please post a Minimal, Complete, and Verifiable example and the complete error messages from the compiler.

    – R Sahu
    Mar 23 at 4:39






  • 1





    "I have tried most suggestions that I can find on websites, but none of them works." It's hard for us to help you when we can't try suggestions, get error messages with our preferred compiler, simplify the code to see if the error goes away, and so on.

    – David Schwartz
    Mar 23 at 5:20











  • I had to make a lot of assumptions about your Node and Word classes (many of them bad coding style; e.g. you should use = default for constructors and destructors when possible, or in this case just use the Rule of Zero and don't explicitly define them at all), but when I did everything compiled perfectly. Please share the full error message and see if you can provide a complete (non-)working minimal example.

    – Daniel H
    Mar 23 at 5:21







3




3





Please post a Minimal, Complete, and Verifiable example and the complete error messages from the compiler.

– R Sahu
Mar 23 at 4:39





Please post a Minimal, Complete, and Verifiable example and the complete error messages from the compiler.

– R Sahu
Mar 23 at 4:39




1




1





"I have tried most suggestions that I can find on websites, but none of them works." It's hard for us to help you when we can't try suggestions, get error messages with our preferred compiler, simplify the code to see if the error goes away, and so on.

– David Schwartz
Mar 23 at 5:20





"I have tried most suggestions that I can find on websites, but none of them works." It's hard for us to help you when we can't try suggestions, get error messages with our preferred compiler, simplify the code to see if the error goes away, and so on.

– David Schwartz
Mar 23 at 5:20













I had to make a lot of assumptions about your Node and Word classes (many of them bad coding style; e.g. you should use = default for constructors and destructors when possible, or in this case just use the Rule of Zero and don't explicitly define them at all), but when I did everything compiled perfectly. Please share the full error message and see if you can provide a complete (non-)working minimal example.

– Daniel H
Mar 23 at 5:21





I had to make a lot of assumptions about your Node and Word classes (many of them bad coding style; e.g. you should use = default for constructors and destructors when possible, or in this case just use the Rule of Zero and don't explicitly define them at all), but when I did everything compiled perfectly. Please share the full error message and see if you can provide a complete (non-)working minimal example.

– Daniel H
Mar 23 at 5:21












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310590%2fcreate-an-unordered-map-with-custom-object-as-key%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310590%2fcreate-an-unordered-map-with-custom-object-as-key%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?