title: c++ dynamic struct inside a class
body: <p>I'm still trying to learn C++ and my first approach came from a non object side of C. So I want to redo my structs and make use of the class data structure. I've come up with this. </p>
  
  <p>In Gradebook.h</p>
  
  <pre><code>class Gradebook {
  public:
  //default constructor, initializes variables in private
  Gradebook();
  //accessor constructor, access members in private
  private:
  struct Student {
      int student_id;
      int count_student;
      string last;
      string first;
      };
  struct Course {
      int course_id;
      int count_course;
      string name;
      Student *students;
      };
  };
  </code></pre>
  
  <p>In my Gradebook.cpp</p>
  
  <pre><code>Gradebook::Gradebook() {
  
   Course *courses = new Course;
   courses-&gt;students = new Student;
  
   courses-&gt;count_course = 0;
   courses-&gt;course_id = 0;
  
   courses-&gt;students-&gt;count_student = 0;
   courses-&gt;students-&gt;student_id = 0;
  
  }
  </code></pre>
  
  <p><strong>My Design</strong></p>
  
  <p>I want to dynamically create <code>x_amount</code> to <code>Students</code> and <code>x_amount</code> of <code>Courses</code>.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>I don't understand how to access my struct so I can start to add courses and students inside my struct.</p>
  
  <p>I believe I can do the rest if I can try to access my struct and manipulate the members inside it. I've tried: </p>
  
  <pre><code>void Gradebook::newCourse(Course *courses) {
  
    //do stuff
  
  }
  </code></pre>
  
  <p>When I try to compile it I get all kinds of errors: </p>
  
  <pre><code>In file included from gradebook.cpp:2:
  ./gradebook.h:9:18: error: C++ requires a type specifier for all declarations
          void newCourse(&amp;Course);
  
  gradebook.cpp:39:17: error: out-of-line definition of 'newCourse' does not match any
        declaration in 'Gradebook'
  void Gradebook::newCourse(Course *courses) {
  
  
  2 errors generated.
  In file included from main.cpp:4:
  ./gradebook.h:9:18: error: C++ requires a type specifier for all declarations
          void newCourse(&amp;Course);
  </code></pre>
  
  <p>Any help for this noob is appreciated. Thanks in advance!</p>