有人能告诉我为什么我得到这个错误,即使参数是正确的
Can someone tell me why am i getting this error even though the arguments are correct?
这是我试图提交的。h文件,由于相同类型的错误,测试人员不让它通过。
#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
这些是我不明白的错误。我已经提供了所有需要的参数。
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
这是ICTCourse.cpp文件
#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) <<" "<< " | ";
}
}
这个日志说,在文件M2CourseTester.cpp
第19行和第25行,类ICTCourse
的构造函数被调用了一组错误的参数。
可能有类似这样的代码:
ICTCourse* course = new ICTCourse("", "maths", 1, 1);
构造函数需要5个形参:
-
const char [5]
型const char* courseCode
-""
-
int credits
-1
类型int
-
int studyload
-1
类型int
-
char* computerSystem
- missing
const char [1]
型const char* coursetitle
- "maths"
你需要为构造函数提供第五个参数。
乌利希期刊指南。以下语法不是默认参数:
ICTCourse::ICTCourse()
:Course() {
strcpy(computerSystem_, "matrix");
}
你可以在这里阅读默认参数
它看起来像这样:
//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
相关文章:
- C++声明模板参数阴影模板参数错误
- 为什么 CRTP 模板C++给出无效参数错误?
- (C/C++)fscanf_s从txt文件以字符形式读取数组时缺少整数参数错误
- 参数错误可能与类型不匹配有关?
- printf 和 strftime 的参数错误无效
- 如何修复"ctypes"。参数错误:参数 2:<键入"异常.类型错误">:RaspberryPi 中的错误类型"错误
- 如何修复"没有重载函数需要 2 个参数"错误C++
- 术语不计算为函数采用 1 个参数错误?
- 从带有 getline() 的文件读入一行上有多个信息得到无效参数错误
- 为什么我不能像使用 std::string::size_type 那样使用 QList::size_type?(模板参数错误)
- cudaFreeHost() 无效参数错误
- 精神语法不会编译:函数模板参数错误?
- C 功能具有参考参数错误的迭代器错误.寻求解释
- 使用getDefaultCommConfig使用无效的参数错误
- C++ 可变参数模板和模板模板参数:错误:模板参数列表中参数 1 处的类型/值不匹配
- 使用SWIG生成的Python库时,向量分配器参数错误
- 错误C2664:无法转换参数错误
- C 作为参数错误的功能
- 命令行参数错误
- 增强Python参数错误