mardi 5 mai 2015

C++ struct - pointer to pointer and dynamic array

I want to implement a tree trie and insert an example value into the key variable I am using a pointer to pointer and creating a dynamic array of 100 elements but my application crashes after starting.

#include<iostream>
using namespace std; 

struct node {
  int key;
  node **children;          
};

int main() {
  node *child;          
  child = new node;
  child->children = new node *[100];
  child->children[20]->key = 90;        
  cout<<child->children[20]->key;

  return 0;
}

Aucun commentaire:

Enregistrer un commentaire