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.
In Gradebook.h
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;
};
};
In my Gradebook.cpp
Gradebook::Gradebook() {
Course *courses = new Course;
courses->students = new Student;
courses->count_course = 0;
courses->course_id = 0;
courses->students->count_student = 0;
courses->students->student_id = 0;
}
My Design
I want to dynamically create x_amount
to Students
and x_amount
of Courses
.
Problem
I don't understand how to access my struct so I can start to add courses and students inside my struct.
I believe I can do the rest if I can try to access my struct and manipulate the members inside it. I've tried:
void Gradebook::newCourse(Course *courses) {
//do stuff
}
When I try to compile it I get all kinds of errors:
In file included from gradebook.cpp:2:
./gradebook.h:9:18: error: C++ requires a type specifier for all declarations
void newCourse(&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(&Course);
Any help for this noob is appreciated. Thanks in advance!