PUSSY_LICKING_LOLI_69's blog

By PUSSY_LICKING_LOLI_69, history, 2 months ago, In English

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?

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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) {};
};