How can I overload equal method to make different objects have same hashcode value in unordered_multimap?

How do you make a constructor? (Novice Level)?

  • I am currently working on this problem for a class and i can't get passed the part where i have to make a constructor. Can anybody show me how to do this problem or explain to me how to make a constructor? Thank you! Write the definition of a class Counter containing: An instance variable named counter of type int . A constructor that takes one int argument and assigns its value to counter A method named increment that adds one to counter . It does not take parameters or return a value. A method named decrement that subtracts one from counter . It also does not take parameters or return a value. A method named getValue that returns the value of the instance variable counter .

  • Answer:

    class Counter { int counter ; void increment() { counter++ ; } void decrement() { counter-- ; } int getValue() { return counter ; } public: Counter(int x) // constructor has same name as that of class and NO return type { counter=x; } } ; Hope it helps....

Chris at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

copy and paste this and it will work perfect public class Counter { private int counter; public Counter(int x) { counter=x; } public void increment() { counter++ ; } public void decrement() { counter-- ; } public int getValue() { return counter ; } }

David

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.