Can someone explain this structure?

1
2
3
4
5
6
struct node
{
    node(int data_p) { data=data_p; next=0; }
    int data;
    node *next;
};


Line 3 is the problem for me. Have absolutely NO idea what it means
I think it's a constructor, or inline function thing.

brb let me check my textbook

ok i have no idea what it is nvm

actually i think it's a constructor (constructors initialize the member variables in a structure or class i think), but in this case the function is defined inline

lawl, i may be wrong though, of course
Last edited on
It is a constructor.
Line 3 is indeed a constructor. A struct in C++ is virtually identical to a class:

http://cplusplus.com/doc/tutorial/classes/

Its as if that line shouldn't be there. Without it, it bears all the hallmarks of a simple node i.e. a data member and a pointer to a structure of the same type.
Oh OK. That means we are entering the realms of C++.

I was hoping I could stick to C. Nevermind, ill never and dont want to understand it.
Last edited on
Topic archived. No new replies allowed.