-3

for the following code I am getting error

receive_cmd.cpp:12:40: error: no match for 'operator==' in 'tmp_cmd == gold_rom[tmp_cmd.cmd::cmd_id]'

void tb::receive_cmds(){
 cmd tmp_cmd;
 cmd gold_rom[128];
 wait(1, SC_NS);
 cmd_error = false;
 while(true){
 tmp_cmd = tb_cmd_in->read();
 if (tmp_cmd == gold_rom[tmp_cmd.cmd_id]) {
 cout << sc_time_stamp() << " " << name();
 cout << ": received correct result for: " << tmp_cmd << endl;
 }
 else {
 cmd_error++;
 cout << sc_time_stamp() << " " << name();
 cout << ": ERROR command = "<< tmp_cmd
 << ", should be: "
 << gold_rom[tmp_cmd.cmd_id];
 }
 num_cmds --;
 cmd_received.notify();
 }
}
AmeyaVS
  • 814
  • 10
  • 26
uzmeed
  • 21
  • 5

2 Answers2

1

You need to explicitly provide an overload for bool cmd::operator==(const cmd &).

This is C++, not Java. There's no automatic comparison operator generated for you. You should write one for every comparison that involves user-defined types that you want to use. Here's a simple example:

class A {
    public:
    int a;
    A(int _a) : a(_a) {}
    bool operator == (const A & ref) const;
};


bool A::operator == (const A & ref) const {
    return this->a == ref.a;
}

A x(5), y(5), z(7);
bool b1 = (x == y); // b1 is true
bool b2 = (x == z); // b2 is false
iBug
  • 35,554
  • 7
  • 89
  • 134
  • 1
    For the record, Java doesn't create automatic comparison operators, it just twists the meaning of `==` to automatically compare pointers to objects. Java also doesn't automatically create a correct `equals` method. You have to do it all yourself, or at least with the help of the IDE. So that situation is very much comparable (no pun intended) to C++. – Christian Hackl Jan 05 '18 at 16:20
1

You are using an object of type cmd, and you are doing a == comparison on it.
You didn’t show the class implementation but it seems like this class does not have a definition for the equality comparison operator.
Therefore, the compiler is telling you that it doesn’t know how to do this equal comparison

Aganju
  • 6,295
  • 1
  • 12
  • 23