Thread: no match for 'operator=='

  1. #1
    Registered User
    Join Date
    Dec 2017
    Posts
    10

    no match for 'operator=='

    for the following code I am getting the error

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

    Code:
    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();
     }
    }
    please help to resolve

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    You failed to have 'operator==' for class "cmd".

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Dec 2017
    Posts
    10
    Thanks Tim

    I know that I failed to have operator for class cmd

    and worked out that a code similar to
    Code:
    bool operator == (const X... &p1, const y...&p2)
    	{
    	   if( / * evaluate their equality */)
    	     return true;
    	   else
    	     return false;
    	}
    is to be used

    being newbie to C I m unable use it

    can u please guide how can I do it

    my cmd.h is

    Code:
    #ifndef _CMD_H
    #define _CMD_H
    
    
    
    
    enum cmd_t{ADD,SUB};
    
    
    class cmd{
    
    
    public:
    
    
    
    
    	cmd_t command;
    
    
    	int op_1;
    	int op_2;
    
    
    	int cmd_id;
    
    
    	cmd(): command(ADD),op_1(0),op_2(0),cmd_id(0) {}
    
    
    	cmd (cmd_t c, int d0, int d1, int id):
    
    
    	command(c),op_1(d0),op_2(d1),cmd_id(id){}
    
    
    
    
    
    
    };
    
    
    std::ostream& operator<<(std::ostream& os, cmd& c);
    
    
    #endif

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    First you are writing C++ not C code!

    I will let someone else try to help you; you are a person who looks to need an expert to help.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Jun 2017
    Posts
    157
    One way to do is:
    Code:
    class cmd 
    {
    public:
      cmd_t command;
      int op_1;
      int op_2;
      int cmd_id;
    
      cmd() : command(ADD), op_1(0), op_2(0), cmd_id(0) {}
      cmd(cmd_t c, int d0, int d1, int id) :
      command(c), op_1(d0), op_2(d1), cmd_id(id) {}
    
      bool operator==(const cmd& other);
    };
    
    bool cmd::operator==(const cmd& other)
    {
      return op_1 == other.op_1;
      // TO DO check all conditions
    }
    BTW I think you really should get a good book about C++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. no match for operator>> !?
    By Spyser in forum C++ Programming
    Replies: 2
    Last Post: 02-21-2012, 08:00 AM
  2. no match for operator =
    By vaibhavs17 in forum C++ Programming
    Replies: 4
    Last Post: 03-30-2009, 12:38 PM
  3. no match for 'operator>>'
    By Taka in forum C++ Programming
    Replies: 3
    Last Post: 03-30-2009, 12:17 AM
  4. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  5. no match for operator << ??
    By neoragexxx in forum C++ Programming
    Replies: 6
    Last Post: 05-01-2006, 05:02 PM

Tags for this Thread