typedef struct _node node;

typedef struct _node
{
	int is_leaf;
	node child[THRESHOLD_ITEM_SET];
	list<item_set> candidate_set;
} node;

or this:

typedef struct _node
{
	int is_leaf;
	struct _node child[THRESHOLD_ITEM_SET];
	list<item_set> candidate_set;
} node;

I am getting error:

error: field ‘child’ has incomplete type

I don't want to declare child as pointer. Is this possible to keep it as array instead of pointer?

Is this me or does this look like C++

list<item_set> candidate_set;

Nope. Not just you. Please clarify, johndoe444

I dont't think you can define it like these.
you can think , if you define like this, what's the size of the struct _node. it's infinite !!!!!!!! so the compiler can not give you enough memory

typedef struct _node node;

typedef struct _node
{
	int is_leaf;
	node child[THRESHOLD_ITEM_SET];
	list<item_set> candidate_set;
} node;

No you can not.
Try to calculate a size of this structure. Seems to be infinite, don't you think so? In a recursive structure definition the recursive reference must be a pointer:

typedef struct _node node;

struct _node {
    int is_leaf;
    node * child[THRESHOLD_ITEM_SET];
    // Omitting the C++ism
};

Dude, the problem is with structure which is very much C. The template thing is totally irrelevant here because the problem would still arise even if the list attribute is removed. My reputation is 1 and guys have reputation is 1+. And if I post it to the C++ forum then the admin would definitely kick out to this forum. Why do you pick on a poor guy like me? :)

is it something like this?

#include <stdio.h>

 #define MAX 4


 struct part {
     int number;
     char name[10];
 } data[MAX] = {1, "Erap",
                2, "Gloria",
                3, "Aquino",
                4, "Rizal"
                };


 struct part *p_part;

 int count;

 main()
 {


     p_part = data;

     for (count = 0; count < MAX; count++)
     {
         printf("At address %d: %d %s\n", p_part, p_part->number,
                 p_part->name);
         p_part++;
     }

     return 0;
 }

or put your structure in function

/*passing structure in function*/

#include <stdio.h>

struct data{
    float amount;
    char fname[30];
    char lname[30];
} rec;

void print_rec(struct data x);

main()
{

    printf("Enter the first and last names,\n");
    printf("separated by a space: ");
    scanf("%s %s", rec.fname, rec.lname);

    printf("\nEnter the salary: ");
    scanf("%f", &rec.amount);

    print_rec( rec );

    return 0;
}

void print_rec(struct data x)
{
    printf("\nEmployee %s %s salary is $%.2f.\n", x.fname, x.lname,
            x.amount);
}

Edited 6 Years Ago by phpbeginners: n/a

i know I just want to share some technique if you can split your struct and put it in a function. :-)

try this

typedef struct _node *node; /*put an asterisk*/

I don't want to declare child as pointer. Is this possible to keep it as array instead of pointer?

A bit unclear to me will you be writing C or C++. But anyway, if C++ is allowed, you might store the child nodes in a std::vector, so ..

struct node
{
  std::vector<node> child;
};

the problem is with structure which is very much C

Hmm, a structure is just as much about C as it is about C++, so I suppose no 'admin' would kick you anywhere.

This article has been dead for over six months. Start a new discussion instead.