主题:使用 &时的一个错误,请大家帮帮忙
定义了一个类
class Course
{
public:
course(const string &coursename);
string getcoursename();
void addstudent(const string &student);
string *getstudents();
int getnumberofstudents();
private:
string coursename;
string students[100];
int numberofstudents;
};
一部分实现为:
#include<iostream>
#include"course.h"
using namespace std;
Course::course(const string &coursename)
{
numberofstudents=0;
this->coursename1=coursename;
}
再main中定义了对象
#include<iostream>
#include"course.h"
using namespace std;
void main()
{
Course course2("datasheet");
}
报错::error C2664: '__thiscall Course::Course(const class Course &)' : cannot convert parameter 1 from 'char [10]' to 'const class Course &'
Reason: cannot convert from 'char [10]' to 'const class Course'
No constructor could take the source type, or constructor overload resolution was ambiguous
请大家帮帮我 谢谢
class Course
{
public:
course(const string &coursename);
string getcoursename();
void addstudent(const string &student);
string *getstudents();
int getnumberofstudents();
private:
string coursename;
string students[100];
int numberofstudents;
};
一部分实现为:
#include<iostream>
#include"course.h"
using namespace std;
Course::course(const string &coursename)
{
numberofstudents=0;
this->coursename1=coursename;
}
再main中定义了对象
#include<iostream>
#include"course.h"
using namespace std;
void main()
{
Course course2("datasheet");
}
报错::error C2664: '__thiscall Course::Course(const class Course &)' : cannot convert parameter 1 from 'char [10]' to 'const class Course &'
Reason: cannot convert from 'char [10]' to 'const class Course'
No constructor could take the source type, or constructor overload resolution was ambiguous
请大家帮帮我 谢谢