0
votes

Hi all I have this code -

typedef struct signal_declairation{

  //these are for 2001 type declairation
  bool is_array;
  int array_start, array_end;
  PORT_ATTRIBUTE port_attribute; //port direction
  string port_type;              //logic, UDT, wire, accept every thing

  //this is common to 2001 and normal
  string port_name;

  //dumper method
  friend ostream& operator<<(ostream &out, signal_declairation &m_signal_declairation);


} SIGNAL_DECLAIRATION;

std::ostream& operator<< (ostream &out, signal_declairation &m_signal_declairation)
{
  string port_direction;
  switch(m_signal_declairation.port_attribute){
  case INPUT: port_direction = "input";
    break;
  case OUTPUT: port_direction = "output";
    break;
  case INOUT: port_direction = "inout";
    break;
  }

  if(m_signal_declairation.is_array==true){

    out << " Port Name = " << m_signal_declairation.port_name 
    << " Port Direction = " << m_signal_declairation.port_attribute
    << " Port type = " << m_signal_declairation.port_type
    << " This is an arrayed port :: Array Start = " << m_signal_declairation.array_start 
    << " Array End = " << m_signal_declairation.array_end ;



    }else{

    out << " Port Name = " << m_signal_declairation.port_name 
    << " Port Direction = " << m_signal_declairation.port_attribute
    << " Port type = " << m_signal_declairation.port_type;

  }

  return out;
}

When I try and compile, I get errors that look like this -

parser_globals.h: In function ‘std::ostream& operator<<(std::ostream&, signal_declairation&)’: parser_globals.h:53:9: error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream}’ and ‘const char [14]’) out << " Port Name = " << m_signal_declairation.port_name

Not sure why I am not able to pass class members to << as shown above. Can anyone help ???? Thanks Raj

3

3 Answers

0
votes

If you had provided the complete error messages that you get and not just a small snippet, things would have been easier.

Based on what you provided so far, it looks like you might have forgot to include the necessary header(s) for the standard streams, e.g.:

#include <iostream>

This would cause the compiler to not find the operator<< overloads for the base types or the types from the standard library.

0
votes

change your overload definition :

std::ostream& operator<< (ostream &out, signal_declairation &m_signal_declairation)

by std::ostream& operator<< (ostream &out,const signal_declairation &m_signal_declairation) .

Dont forget the prototype too.

0
votes

The compiler complains about the ‘const char [14]’) out << " Port Name = ". It looks like the compiler cannot see the " Port Name - " as string, rather it sees it as character array. Have you include ?