Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

im getting this why? i declared it. error code// ./h23.h:16:17: error: use of un

ID: 3598375 • Letter: I

Question

im getting this why? i declared it.

error code//

./h23.h:16:17: error: use of undeclared identifier 'Student'
std::vector<Student *> students;
^
./h23.h:16:26: error: expected expression
std::vector<Student *> students;
^

#ifndef H23_H_
#define H23_H_
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
////////////// DEFINE YOUR STRUCTURES HERE ///////////////////////
struct Course
{
std::string name;
std::vector<Student *> students;
};

struct Student
{
std::string name;
std::vector<Course *> courses;

};

/**
Enrolls a student in a course.
@param s the student to entroll.
@param c the course to enroll the student in.
*/
void enroll(Student* s, Course* c);

/**
Prints a student and the courses enrolled in.
@param o the stream to print the output on
@param s a pointer to a const Student object
@return the output stream
*/
std::ostream& operator<<(std::ostream& out, const Student* s);


/**
Prints a course name and the students enrolled in it.
@param o the stream to print the output on
@param s a pointer to a const Course object
@return the output stream
*/
std::ostream& operator<<(std::ostream& out, const Course* s);

#endif

Explanation / Answer

struct are in there own tags so you have to use struct whenever you want to refer declared structure

for example instead of Student you will be using struct Student

Here is fixed code.

#ifndef H23_H_
#define H23_H_
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
////////////// DEFINE YOUR STRUCTURES HERE ///////////////////////
struct Course
{
std::string name;
std::vector<struct Student *> students;
};

struct Student
{
std::string name;
std::vector<struct Course *> courses;
};


/**
Enrolls a student in a course.
@param s the student to entroll.
@param c the course to enroll the student in.
*/
void enroll(struct Student* s, struct Course* c);
/**
Prints a student and the courses enrolled in.
@param o the stream to print the output on
@param s a pointer to a const Student object
@return the output stream
*/
std::ostream& operator<<(std::ostream& out, const struct Student* s);

/**
Prints a course name and the students enrolled in it.
@param o the stream to print the output on
@param s a pointer to a const Course object
@return the output stream
*/
std::ostream& operator<<(std::ostream& out, const struct Course* s);
#endif