简体   繁体   中英

Can someone tell me why am i getting this error even though the arguments are correct?

This is the .h file which i'm trying to submit and the tester is not letting it through because of errors of the same type.

#ifndef SICT_ICTCOURSE_H__
#define SICT_ICTCOURSE_H__

#include "Course.h"

namespace sict {
    class ICTCourse : public Course {
    private:
        char computerSystem_[6 + 1];

    public:
        ICTCourse();
        ICTCourse(const char* courseCode, const char* coursetitle, int credits, int studyload, char* computerSystem);

        const char* getComputerSystem() const;
        void setComputerSystem(const char* value);
        void display(ostream&);
    };
}
#endif

These are the errors which i do not understand. I've provided all the arguments that are needed.

M2CourseTester.cpp: In function âbool isEmptyTest1()â:
M2CourseTester.cpp:19:38: error: no matching function for call to    âsict::ICTCourse::ICTCourse(const char [1], const char [6], int, int)â
M2CourseTester.cpp:19:38: note: candidates are:
ICTCourse.h:20:3: note: sict::ICTCourse::ICTCourse(const char*, const char*, int, int, char*)
ICTCourse.h:20:3: note:   candidate expects 5 arguments, 4 provided
ICTCourse.h:18:3: note: sict::ICTCourse::ICTCourse()
ICTCourse.h:18:3: note:   candidate expects 0 arguments, 4 provided
ICTCourse.h:9:8: note: sict::ICTCourse::ICTCourse(const sict::ICTCourse&)
ICTCourse.h:9:8: note:   candidate expects 1 argument, 4 provided
M2CourseTester.cpp: In function âbool isEmptyTest2()â:
M2CourseTester.cpp:25:37: error: no matching function for call to âsict::ICTCourse::ICTCourse(const char [5], const char [1], int, int)â
M2CourseTester.cpp:25:37: note: candidates are:
ICTCourse.h:20:3: note: sict::ICTCourse::ICTCourse(const char*, const char*, int, int, char*)
ICTCourse.h:20:3: note:   candidate expects 5 arguments, 4 provided
ICTCourse.h:18:3: note: sict::ICTCourse::ICTCourse()
ICTCourse.h:18:3: note:   candidate expects 0 arguments, 4 provided
ICTCourse.h:9:8: note: sict::ICTCourse::ICTCourse(const sict::ICTCourse&)  
ICTCourse.h:9:8: note:   candidate expects 1 argument, 4 provided

This is the ICTCourse.cpp file

#include "ICTCourse.h"

namespace sict {
    ICTCourse::ICTCourse():Course() {
        strcpy(computerSystem_, "matrix");
    }

    ICTCourse::ICTCourse(const char* courseCode, const char* courseTitle, int credits, int studyLoad, char* computerSystem){
        courseCode_Setter(courseCode);
        courseTitle_Setter(courseTitle);
        credits_Setter(credits);
        studyLoad_Setter(studyLoad);
        strcpy(computerSystem_, computerSystem);
    }

    const char* ICTCourse::getComputerSystem() const{
        return computerSystem_;
    }

    void ICTCourse::setComputerSystem(const char* value){
        strncpy(computerSystem_, value, 6);
    }

    void ICTCourse::display(ostream& pout){

        pout << left << setw(MAX_COURSECODE_LEN) << getCourseCode() << " | " << left << setw(20) << getCourseTitle() << " | " << right << setw(6) << getCredits() << " | " << right << setw(4) << getStudyLoad() << " | " << left << setw(6) << computerSystem_ << " | " << setw(4) <<"  "<< " | ";

    }
}

This log says that in the file M2CourseTester.cpp On lines 19 and 25 the constructor of class ICTCourse is invoked with wrong set of arguments.

There is probably code similar to this:

ICTCourse* course = new ICTCourse("", "maths", 1, 1);

While the constructor expects 5 parameters:

  • const char* courseCode - "" of type const char [5]
  • const char* coursetitle - "maths" of type const char [1]
  • int credits - 1 of type int
  • int studyload - 1 of type int
  • char* computerSystem - missing

You need to provide fifth argument to constructor.


UPD.
Following syntax is not a default argument:

ICTCourse::ICTCourse()
  :Course() {
    strcpy(computerSystem_, "matrix");
}

You can read about default arguments here

It would look like this:

//ICTCourse.h
...
ICTCourse(const char* courseCode,  
  const char* coursetitle,  
  int credits, 
  int studyload,  
  char* computerSystem = "matrix");
  //                   ^^^^^^^^^^ default value here
...
//ICTCourse.cpp
...
ICTCourse::ICTCourse(const char* courseCode,  
  const char* courseTitle,  
  int credits,  
  int studyLoad,  
  char* computerSystem /* = matrix*/){
  //                   ^^^^^^^^^^ no value here
  //                   good practice to keep it as a comment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM