回 帖 发 新 帖 刷新版面

主题:使用 &时的一个错误,请大家帮帮忙

定义了一个类
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
请大家帮帮我 谢谢

回复列表 (共2个回复)

沙发

构建函数第一个字母小写了

板凳

你好.我是全职网赚工作者.
如果你有时间有电脑.会打字.
想在网络上创业.请联系我..
项目绝对真实.详情QQ空间资料
加盟请联系 QQ909065437

我来回复

您尚未登录,请登录后再回复。点此登录或注册