-1

I am currently trying to create a simple implementation of a Module class and a Student class in c++. These classes will incorporate specific modules and the individual students enrolled in them. However, I can't seem to get round this particular error message whenever I try to make a Module or Student object.

It will probably be something simple I missed but I have uploaded my header and source files below. Please help, this is driving me crazy. Thanks in advance.

student.h:

#include "stdafx.h"
#include <string>

class Student {

public:
    Student(std::string, std::string, int);
    std::string getName() const { return name; }
    std::string getDegree() const { return degree; }
    int getLevel() const { return level; }

private:
    std::string name;
    std::string degree;
    int level;
};

module.cpp:

// student.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "module.h"
#include <vector>
#include <iostream>
#include <string>

using namespace std;

void Module::enrol_student(Student studentY) {

    students.push_back(studentY);
}

void Module::attendance_register() {

    string nameX;

    cout << "Attendance Register:\n" << endl;

    for (int i = 0; i < students.size(); i++) {
        Student studentX = students.at(i);
        nameX = studentX.getName();
        cout << nameX << endl;
    }
}

module.h:

#include "stdafx.h"

#include "student.h"
#include <string>
#include <vector>

class Module {

public:
    Module(std::string, std::string, std::vector<Student>);
    std::string getModCode() { return modCode; }
    std::string getModTitle() { return modTitle; }
    void attendance_register();
    void enrol_student(Student);


private:
    std::string modCode;
    std::string modTitle;
    std::vector<Student> students;

};

testCode.cpp

// testCode.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}


#include "module.h"

#include <vector>
#include <iostream>
#include <string>

using namespace std;

int main() {

    //Initial Test Data
    Student student1("Arthur Smith", "Computer Science", 1);

    return 0;

}

1 Answers1

1

You need to define the constructors you declared in your classes. In student.cpp you need something like this:

Student::Student(std::string name, std::string degree, int level) : name(name), degree(degree), level(level)
{
}

This will initialise the members with the values provided.

And similar for Module.

Alexander Balabin
  • 2,055
  • 11
  • 13