expected identifier or ‘(’ before ‘int’: struct tagNode( int _v )
this is because of the unexpected struct when you compile in C++
A valid version of your code in C++ can be:
struct tagNode
{
int v, f;
tagNode *next;
tagNode (int _v)
{
v = _v;
next = NULL;
}
};
but
- what about f ?
- the constructor can also be
tagNode(int _v) : v(_v), next(NULL) {}
- and you have a pointer so I recommend you to look at the rule of three
There is no constructor/methods in C so the equivalent of your code in C can be :
#include <stdlib.h>
struct tagNode
{
int v, f;
struct tagNode * next;
};
struct tagNode * alloc(int _v)
{
struct tagNode * r = malloc(sizeof(struct tagNode));
r->v = _v;
r->next = NULL;
return r;
}