title: Error in assignment of member in read-only object
body: <p>I am working on worm_sim simulater , ubuntu, gcc, codeblocks IDE</p>
  
  <p>traffic_source.h file</p>
  
  <pre><code>class Traffic_source : public Buffer_owner, public Connector, public Addressee{
  private:
      static unsigned int id_base;
      unsigned int id;
      unsigned int packet_size;
      unsigned int flit_size;
      double packet_generating_rate;
      int pkt_id;
      traffic_source_state ts_state;
      double* packet_to_destination_rate;
      Traffic_mode traffic_mode;
      int period;                // period for packet generation using trace_file
      ifstream trace_file;
      int trace_file_loop_cnt;   // how many times we have gone over the trace file so far
      bool trace_file_empty;
      ofstream trace_dump;       // trace file to dump out
  
      typedef struct Message {
          int timestamp;
          unsigned int destination;
          unsigned int size;
      } Message, *pMessage;
  
      Message pre_fetched_message;
      bool get_next_message(Message &amp; msg);
  
      unsigned int get_destination_uniform(void) const; 
      unsigned int get_destination_transpose1(void) const;
      unsigned int get_destination_transpose2(void) const;
      unsigned int get_destination_hotspot(void) const;
      unsigned int get_destination_customized(void) const;
  
      void generate_a_packet(unsigned int dst_id);
      void generate_packets(const Message &amp; rec);
  
  public:
      Traffic_source(Position p, int buf_sz);
      ~Traffic_source();
      bool can_send(void) const;
      bool can_receive(void) const { return false; }
      bool send(void);
      bool receive(class Flit * a_flit) { return false; }
      class Connector * get_receiver(void) const; 
  
      static void reset_id_base(void) { id_base = 0; }
  
      void tick(void);
  
      /* traffic control routines */
      void set_packet_generating_rate(double r);
      void set_packet_to_destination_rate(unsigned int dst_id, double rate);
      double get_packet_to_destination_rate(unsigned int dst_id) const;
      double get_total_packet_injection_rate(void) const;
      int set_trace_file(char * file_name);
      bool has_trace_file(void) { return (trace_file.is_open()); }
      int get_id(void) const { return id; }
  };
  </code></pre>
  
  <p>traffic_source.cpp</p>
  
  <pre><code>Traffic_source::Traffic_source(Position p, int buf_sz) : Buffer_owner(buf_sz), Addressee(p) {
      id = id_base ++;
      packet_generating_rate = param.packet_generating_rate;
      packet_size = param.flits_per_packet;
      flit_size = param.flit_size;
      traffic_mode = param.traffic_mode;
      period = 0;
      packet_to_destination_rate = 0;
      pkt_id = 0;
      ts_state = OFF_
  
      if (param.dump_traffic_source_trace) {
          char file_name[20];
          sprintf(file_name, "%d.trace", id);
          trace_dump.open(file_name);
          if (!trace_dump.is_open() || !trace_dump.good()) {
              cerr &lt;&lt; "Error in opening file " &lt;&lt; file_name &lt;&lt; " for trace dumping" &lt;&lt; endl;
              exit(-1);
          }
          trace_dump &lt;&lt; "PERIOD\t" &lt;&lt; param.simulation_length &lt;&lt; endl;
          trace_dump &lt;&lt; "#Trace file dumped by worm_sim from node " &lt;&lt; id &lt;&lt; endl;
          trace_dump &lt;&lt; "#Folloing lines are with format as:" &lt;&lt; endl
                     &lt;&lt; "#timestamp\t" &lt;&lt; "destination\t" &lt;&lt; "message_size(bits):" &lt;&lt; endl;
      }
  }
  
  bool Traffic_source::can_send(void) const
  {
      int router_id=get_id();
      unsigned int local_availability;
  
      pRouter a_router= param.network-&gt;get_router(router_id);
      local_availability=a_router-&gt;get_port_availability(0);
      //cout&lt;&lt;local_availability&lt;&lt;endl;
      if (buffer.is_empty())
          return false;
      if(local_availability &lt;= 0)
      {
          packet_generating_rate = 0; //error: assignment of member ‘Traffic_source::packet_generating_rate’ in read-only object|
          set_packet_generating_rate(0); // error: passing ‘const Traffic_source’ as ‘this’ argument of ‘void Traffic_source::set_packet_generating_rate(double)’ discards qualifiers [-fpermissive]|
          return false;
      }
  
  
      // This is somehow trick, we need to verify whether the first flit in the fifo
      // is received right in this clock cycle. If so, we can not send it
      const Flit * first_flit = buffer.peek_flit();
      if (first_flit-&gt;arrived_in_this_cycle())
          return false;
  
      pConnector receiver = get_receiver();
  
      if (receiver)
          return receiver-&gt;can_receive();
      else
          return false;
  }
  </code></pre>
  
  <p>the value packet_generating_rate is not const but when i try to modify it either directly or using the set function it give me errors</p>
  
  <pre><code>packet_generating_rate = 0; //error: assignment of member    
   ‘Traffic_source::packet_generating_rate’ in read-only object|
  
  set_packet_generating_rate(0); // error: passing ‘const Traffic_source’ as ‘this’ argument of ‘void Traffic_source::set_packet_generating_rate(double)’ discards qualifiers [-fpermissive]|
  </code></pre>
  
  <p>although it is used on other files with no problem, any suggestion plz</p>