C++构造函数的实例都与参数列表匹配
C++ no instance of constructor matches the argument list.
我无法弄清楚我的代码出了什么问题。我正在尝试从edx完成实验室作业,但是我无法弄清楚为什么我的代码不起作用。作业需要创建学生班级、教师班级和课程班级。我正在尝试找出课程类构造函数,但它不会接受我的教师对象。我使用指针来创建对象,以便为它分配内存空间(我在edx上学到的东西之一,如果我误解了,请告诉我(。所以我尝试在构造函数中使用引用,但它仍然不起作用。这是代码。我使用"未知"作为填充物。
主代码:
#include "stdafx.h"
#include <iostream>
#include <string>
#include "Student.h"
#include "Teacher.h"
#include "Course.h"
using namespace std;
int main()
{
Teacher *teach = new Teacher("Jane", "DoeDoe", 25, "Unknown", "Unknown", "Unknown");
Student *stud1 = new Student();
Student *stud2 = new Student("John", "Doe", 19, "Unknown", "Unknown", "Unknown");
Student *stud3 = new Student("Jane", "Doe", 23, "Unknown", "Unknown", "Unknown");
//Method had two postions. First and Last
stud1->setName("Unknown", "Unknown");
stud1->setAge(20);
stud1->setAddress("Unknown");
stud1->setCity("Unknown");
stud1->setPhone("Unknown");
Course *c = new Course("Intermediate C++", teach, stud1, stud2, stud3);
return 0;
}
课程.h
#pragma once
#include <iostream>
#include "Student.h"
#include "Teacher.h"
#include <string>
using namespace std;
class Course {
private:
string name;
Teacher teacher;
Student student1;
Student student2;
Student student3;
public:
Course(string n, Teacher &t, Student &s1, Student &s2, Student &s3);
~Course();
};
当然.cpp
#include "stdafx.h"
#include "Course.h"
Course::Course(string n, Teacher &t, Student &s1, Student &s2, Student &s3)
{
name = n;
teacher = t;
student1 = s1;
student2 = s2;
student3 = s3;
}
Course::~Course()
{
}
Course(string n, Teacher &t, Student &s1, Student &s2, Student &s3);
希望您将引用传递给t
、s1
、s2
。
Course *c = new Course("Intermediate C++", teach, stud1, stud2, stud3);
在这里你通过teach
这是一个teacher*
.你想
Course *c = new Course("Intermediate C++", *teach, *stud1, *stud2, *stud3);
您可能想阅读有关引用和指针的更多信息
相关文章:
- 概念中的cv限定符需要表达式参数列表
- 在没有参数列表的情况下使用模板名称"Event"无效,模板问题
- 错误 没有与参数列表匹配的重载函数"getline"实例
- std::vector 没有重载函数的实例与参数列表匹配
- 模板参数列表中的 false 在模板初始化期间计算为什么?
- C++模板/别名 - 模板参数列表中参数 1 处的类型/值不匹配
- 构造函数/函数声明参数列表中的统一初始化
- 模板化检查是否存在带有参数列表的类成员函数?
- 如何将类成员方法的参数列表自动填充写入可变参数?
- 带有整数的变量参数列表
- 转发变量参数列表以模拟 std::thread
- 错误:"模板<类_Tp,类_Dp>类 std::unique_ptr"的模板参数列表中参数 1 的类型/值不匹配
- C++-将具有引用的长参数列表重构为结构
- 缺少别名模板C++参数列表
- C++如果两个模板函数都与参数列表匹配,将调用哪个模板
- "extern"声明以及带有和不带参数列表的类模板实例的后续定义
- 使用显式模板参数列表和 [temp.arg.explicit]/3 的函数调用的演绎失败
- 没有函数模板的实例与我不知道为什么的参数列表匹配
- 我可以使用宏自动构建参数列表吗?
- 类成员函数参数列表是否可以依赖于模板参数?