Блог пользователя PUSSY_LICKING_LOLI_69

Автор PUSSY_LICKING_LOLI_69, история, 5 часов назад, По-английски

I've been messing with struct and pointers in C++ and got this problem.

This code gives an error saying " ‘x’ does not name a type " at the line marked below

struct A{
    A *a;
};

struct B{
    A *x;
    x = NULL; // this line gives error
};

What causes this and how do I fix this problem?

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

You should either initialize x when declaring it, or through a constructor like so:

struct A {
    A* a;
};

struct B {
    A* x = NULL;
};

struct C {
    A* x;
    C() : x(NULL) {};
};