此代码无法编译:

typedef struct
{
   int node_id;
   double node_val;
   int activation_type;

   void operator= (const node_info &rhs)
   {
      node_id = rhs.node_id;
      node_val = rhs.node_val;
      activation_type = rhs.activation_type;
   }
   bool operator== (const int val)
   {
      return(node_id == val);
   }

} node_info;

编译错误是

error: unknown type name 'node_info'
void operator= (const node_info &rhs)

请注意, node_info 结构未在上面声明 operator= 的地方声明 .

如果我在没有typedef的情况下定义struct,请使用以下命令

struct node_info
{
  //same as before
};

我的代码编译得很好 . 在第一个版本中, edge_info 名称直到 operator= 声明之后才出现,所以我猜这是编译时出错的原因 . 对此最好的解决方法是什么?