cahuizar
cahuizar

Reputation: 35

Trying to call constructor, receiving "no matching function call" compilation error

I am currently working on creating a program called OOP head of students. the program is supposed to open up a file, read the information, send the information through classes and and properly display the results. I am currently creating information manually from main as a test.

Here is my code:

main.cpp

#include <iostream>
#include <string>
#include <fstream>

#include "School_Academics.h"

using namespace std;


int main(){
    School_Academics n;
     Name name = Name("jack", "lopez");
     Address address = Address("123 some street", "Apt. A", "somecity", "somestate","somezipcode");
    Date dob = Date("01", "12", "1990");//date of birth
    Date dog = Date("07", "11", "2014");//date of graduation  
    School_Academics acad = School_Academics("3.64", "25", dog);
    cout<<n.getStudent()<<endl;
    Student n2 = Student(name, address, dob, acad);
    cout<<n2.getStudent();

}

Student.h

#ifndef STUDENT_H_INCLUDED
#define STUDENT_H_INCLUDED

#include "Address.h"
#include "School_Academics.h"
#include "Name.h"
#include "Date.h"

using namespace std;

class Student{
    private:
        Name name;
        Address address;
        Date dob;
        School_Academics acad;

    public:
        Student();
        Student(Name name, Address address, Date dob, School_Academics acad);
        string getStudent();

};
#endif // STUDENT_H_INCLUDED

Student.cpp

#include <string>
#include <iostream>
#include <cstdlib>
#include <fstream>

#include "Student.h"
using namespace std;

Student::Student(){
    name = Name("","");
    address = Address("","","","","");
    dob = Date("0","0","0");
    acad = School_Academics("0","0","0");
}
Student::Student(Name name, Address address, Date dob, School_Academics acad){
    Student::name = name;
    Student::address = address;
    Student::dob = dob;
    Student::acad = acad;

}

string Student::getStudent(){
    name.getName();
    address.getAddress();
    acad.getSchool_Academics();
    dob.getDate();
}

School_Academics.cpp

#include <string>
#include <iostream>
#include <cstdlib>
#include <sstream>

#include "School_Academics.h"

School_Academics::School_Academics(){
    GPA = "0";
    credits = "0";
    Date DOG = Date("0","0","0");
}

School_Academics:: School_Academics(string GPA, string credits, Date DOG){
    School_Academics::GPA = GPA;
    School_Academics::credits = credits;
    School_Academics::DOG = DOG;
}


string School_Academics::getSchool_Academics(){
    stringstream ss;
    ss <<"School Academics: GPA: "<<GPA<<" credits: "<<credits<<" Graduate: "<<DOG.getDate()<<endl;
    return ss.str();
}

Date.cpp

#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>

#include "Date.h"

using namespace std;

Date::Date(){
    day = "0";
    month = "0";
    year = "0";
}

Date::Date(string day, string month, string year){
    Date::day = day;
    Date::month = month;
    Date::year = year;
}

string Date::getDate(){
    stringstream ss;
    ss <<"Date: "<< day << "/" << month << "/" << year << endl;
    return ss.str();
}

The Problem:

I am currently having problems sending information from the main.cpp and passing it through the Student.cpp and getting the class Student{}; to get the information from the Date.cpp.

Error Received:

|13|error: no matching function for call to 'School_Academics::School_Academics(const char [1], const char [1], const char [1])'|

If you could please help me resolve the error. Thank you in advance.

Upvotes: 1

Views: 550

Answers (1)

J&#233;r&#244;me
J&#233;r&#244;me

Reputation: 8066

The error comes from your student ctor where you have the following

acad = School_Academics("0","0","0");

The School_Academics ctor with 3 char is not defined. This cause the error.

You probably meant to pass the date you created just above:

Student::Student(){
    name = Name("","");
    address = Address("","","","","");
    dob = Date("0","0","0");
    acad = School_Academics("0","0",dob);
    // or acad = School_Academics("0","0",date());
}

Upvotes: 3

Related Questions