'expected ',' or '...' before 'struct' error

Good day,

I have the first time this kind of error.

// another.h
struct Item {
  QString name = QString();
  QString description = QString();
  QVariant value = QVariant();
  struct Interface {
    uint id = 0;
    uint pos = 0;
  } mkio, uks;
  struct Element {
    float weight = 0;
    struct Range {
      uint from = 0;
      uint to = 0;
    } range;
  int index = 0;
} element;
};

I would like to store this nested struct in a stream. So,

// another.h
QDataStream &operator<<(QDataStream &out, const Item::Interface &interface)
{
  return out << interface.id
             << interface.pos;
}
// and another overload operator>> and operator<<...
// Another fields of the `Item` struct are compiling without any error.

1) error: expected ',' or '...' before 'struct' QDataStream &operator<<(QDataStream &out, const Item::Interface &interface)

2) another.h:34:17: error: expected primary-expression before 'struct'
return out << interface.id
^
another.h:34:17: error: expected ';' before 'struct'
another.h:34:17: error: expected primary-expression before 'struct'



Solution 1:[1]

Somewhere in the code, most likely in a library header, the following (or something very similar to it) is hiding:

#define interface struct

which makes the compiler see this:

QDataStream &operator<<(QDataStream &out, const Item::Interface &struct)
{
  return out << struct.id
             << struct.pos;
}

and become very upset.

Rename the parameter.

Solution 2:[2]

I found the wrong place it is the name of variable “interface" (from the small letter). Renaming it to the i, for example clear the code.

QDataStream &operator<<(QDataStream &out, const Item::Interface &i /*nterface*/)

The type Interface declared in a namespace so change its name hadn't the result.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 molbdnilo
Solution 2 General Grievance