title: Reference cannot be initialized/expression must have type class
body: <p>I'm doing a quick binary tree program as a homework, but I am getting weird errors that I can't seem to figure out how to fix. Normally I'm programming in C#, and C is just slightly different but different enough for me to get confused.</p>
  
  <p>Here is the code that is giving the error:</p>
  
  <pre><code>void SortArray() {//bubble sorting by float value of 'b'
  int flag = 0;
  
  do {
      flag = 1;
  
      for (int i = 0; i &lt; arraySize - 1; i++)
      {
          if (stubList[i].b &gt; stubList[i + 1].b) {
              Swap(stubList[i], stubList[i + 1]);
              flag = 0;
          }
      }
  } while (flag == 0);
  
  printf("Sorted by value of variable 'b'"); _getch(); _getch();
  }
  </code></pre>
  
  <p>And here is the whole script:</p>
  
  <pre><code>#include &lt;conio.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  using namespace std;
  
  struct stub
  {
      char crown[51];//some custom name - can be empty
      float b;//comparable value for tree sort
      int c;//limited by maxint
      stub *l;//left node(normally smaller "b" value than this node)
      stub *r;//right node(normally bigger "b" value than this node)
  };
  
  stub *stubList[255];//empty list of a stub array with a safe casual amount
  int arraySize = 0;
  
  stub *head = NULL;//main stub(first)
  stub *latest = NULL;//latest stub
  
  stub *st = NULL;//used for creating and checking
  
  FILE *fs = NULL;
  char fileName[255];
  
  int maxint = 20;//for var 'c'
  
  void BTreeNodeToArray(stub *s) {
      stubList[arraySize] = s;
  
      arraySize++;
  }
  
  void Swap(stub &amp;s1, stub &amp;s2) {
      stub temp = s2;
  
      s1 = s2;
      s2 = temp;
  }
  
  int MaxMin(int num) {
      int clampedInt = num;
      if (num &lt; 0) clampedInt = 0;
      else if (num &gt; maxint) clampedInt = maxint;
  
      return clampedInt;
  }
  
  //Create a completely new stub with crown, b, and c variables being filled here
  void CreateElement() {
      st = new stub;
      printf("Adding information for node:\n");
      printf("Node name: "); gets_s(st-&gt;crown);
      printf("\n");
  
      float f;
      printf("Node float value (B): "); scanf_s("%f", &amp;f);
      st-&gt;b = f;
      printf("\n");
  
      int d;
      printf("Node integer value (C): "); scanf_s("%d", &amp;d);
      st-&gt;c = d;
      printf("\n");
      st-&gt;c = MaxMin(st-&gt;c);
  
      st-&gt;l = NULL;
      st-&gt;r = NULL;
  }
  
  //creates the very first stub(root/head)
  void CreateFirst() {
      printf("First in tree. Adding root node...\n");
  
      CreateElement();
      head = st;
      latest = head;
      BTreeNodeToArray(head);
  
      printf("Added head stub\ncrown: %s\nValue: %f\nExtra: %d", head-&gt;crown, head-&gt;b, head-&gt;c);
      getchar();
      getchar();
  }
  
  void AddStub() {
      if (head == NULL) {
          CreateFirst();
      }
      else {
          CreateElement();//create newest node
          latest = st;
          st = head;
          int depth = 0;
          while (1) {
              if ((latest-&gt;b &lt;= st-&gt;b)) {//choose left if true
                  printf("Went left\n");
                  depth++;
                  if (st-&gt;l == NULL) {//node free, assign here
                      printf("Node assigned at depth %d\n", depth);
                      st-&gt;l = latest;
                      BTreeNodeToArray(latest);
                      getchar();
                      getchar();
                      break;
                  }
                  else {//loop again with next node
                      //printf("New loop (left)\n");
                      st = st-&gt;l;
                  }
              }
              else {//choose right
                  printf("Went right\n");
                  depth++;
                  if (st-&gt;r == NULL) {//node free, assign here
                      printf("Node assigned at depth %d\n", depth);
                      st-&gt;r = latest;
                      BTreeNodeToArray(latest);
                      getchar();
                      getchar();
                      break;
                  }
                  else {//loop again with next node
                      //printf("New loop (right)\n");
                      st = st-&gt;r;
                  }
              }
          }
      }
  }
  
  void ViewArray() {
      for (int i = 0; i &lt; arraySize; i++)
      {
          printf_s("Node [%d]:\n\tCrown: %s\n\tweight: %f\n\tExta value(0 - %d): %d\n", i, stubList[i]-&gt;crown, stubList[i]-&gt;b, maxint, stubList[i]-&gt;c);
      }
      getchar();
  }
  
  void SortArray() {//bubble sorting by float value of 'b'
      int flag = 0;
  
      do {
          flag = 1;
  
          for (int i = 0; i &lt; arraySize - 1; i++)
          {
              if (stubList[i].b &gt; stubList[i + 1].b) {
                  Swap(stubList[i], stubList[i + 1]);
                  flag = 0;
              }
          }
      } while (flag == 0);
  
      printf("Sorted by value of variable 'b'"); _getch(); _getch();
  }
  
  void ProcessArray() {
      char c = ' ';
      int found = 0;
  
      printf("Process with character: \n"); c = _getch();
  
      if (arraySize &lt;= 0) {
          printf("No List!");
          return;
      }
  
      char chkstr[5];
      for (short i = 0; i &lt; 5; i++)//simple assign to a 'string' 5 times
      {
          chkstr[i] = c;
      }
  
      for (int i = 0; i &lt; arraySize; i++)
      {
          if (strstr(stubList[i]-&gt;crown, chkstr) != NULL) {
              // contains
              printf("B = %f at [%d] \n", stubList[i]-&gt;b, i);
              found++;
          }
      }
  
      if (found &gt; 0) {
          printf("---Found: %d with character %c---", found, c);
      }
      else {
          printf("No elements found with '%c'", c);
      }
      getchar();
  }
  
  void ExportArray() {
      FILE *fs = NULL;
      char fileName[255];
      errno_t err;
  
      printf("Save to file as: \n"); gets_s(fileName);
  
      if (strlen(fileName) == 0) {
          printf("Failed to create file. File name empty!");
          _getch();
          _getch();
      }
  
      err = fopen_s(&amp;fs, fileName, "wb");
      if (err != 0) {
          printf("Failed to create file!!!");
          _getch();
          _getch();
          return;
      }
  
      for (int i = 0; i &lt; arraySize; i++)
      {
          int written = fwrite(&amp;stubList[i], sizeof(stub), 1, fs);
          //fwrite(&amp;gr[i], sizeof(student), 1, fs);
      }
      int numclosed = _fcloseall();
  
      printf("Exported to file: %s", fileName);
      getchar();
  }
  
  void CleanReset() {//reset all values and release memory (function used for import)
      for (int i = 0; i &lt; arraySize; i++)
      {
          delete stubList[i];
      }
  
      arraySize = 0;
      st = NULL;
      head = NULL;
      latest = NULL;
  }
  
  void ImportArray() {
      FILE *fs = NULL;
      char fname[255];
      errno_t err;
  
      printf("Open FIle: "); gets_s(fname);
  
      err = fopen_s(&amp;fs, fname, "rb");
      if (err == 0) {
          CleanReset();
  
          fseek(fs, 0, SEEK_END);
          long size = ftell(fs);
          arraySize = size / sizeof(stub);//get amount of students saved
          fseek(fs, 0, SEEK_SET);
  
          int i = 0;
  
          st = new stub;
          fread_s(&amp;st, sizeof(stub), sizeof(stub), 1, fs);
          stubList[i] = st;
          while (!feof(fs)) {
              i++;
              st = new stub;
              fread_s(&amp;st, sizeof(stub), sizeof(stub), 1, fs);
              stubList[i] = st;
          }
  
          printf("File data imported. Size: %d", arraySize);
          getchar();
          return;
      }
  
      printf("Failed to import file!!!");
      getchar();
  }
  
  void main()
  {
      system("chcp 65001");//use utf8
  
      char izb = 'i';
  
      while (izb != '0') {
          system("cls");
  
          printf_s("1. Add stub\n");
          printf_s("2. View Array\n");
          printf_s("3. Sort Array\n");
          printf_s("4. Process\n");
          printf_s("5. Export array to file\n");
          printf_s("6. Import array from file\n");
          printf_s("0. Exit\n\n");
  
          printf_s("Choose action:\n"); izb = _getch();
  
          switch (izb)
          {
          case '1':
              AddStub();
              break;
          case '2':
              ViewArray();
              break;
          case '3':
              SortArray();
              break;
          case '4':
              ProcessArray();
              break;
          case '5':
              ExportArray();
              break;
          case '6':
              ImportArray();
              break;
          case '0':
              //Exit();
              break;
          }
      }
  }
  </code></pre>