没有合适的默认复制构造函数数可用

为什么定义了构造函数了,编译还是提示“没有合适的默认构造函数可用”?_百度知道
为什么定义了构造函数了,编译还是提示“没有合适的默认构造函数可用”?
高手帮我看一下啊,弄了半天,不知道问题出在哪啊~~#include&iostream&class AboutFriend{ friend class AboutCprivate:public: AboutFriend(int i,int j); void SetM(); void SetN();};AboutFriend::AboutFriend(int i, int j){ m = n =}class AboutConst{ friend void OutPut(AboutConst a);public: AboutConst(int a,int b); AboutConst(AboutConst & t); AboutConst(){}; ~AboutConst(); void Print() void Print(); int GetX(); int GetY(); void UseFriend(int i);private: AboutF};int AboutConst::count = 0;void OutPut(AboutConst a){ cout&&&method OutPut is one of class AboutConst's friend method&&& cout&&a.x&&& &&& a.y&&}AboutConst::AboutConst(int a, int b){ x = y = count++; }AboutConst::AboutConst(AboutConst & t){ cout&&&拷贝构造函数被调用:&&& x = t.x; y = t.y; count++;}AboutConst::~AboutConst(){ cout&&&析构函数调用:&&& count--;}void AboutConst::Print() const{ cout&&&the method p&&&
cout&&&const object can only call const method!&&&}void AboutConst::Print(){ cout&&&the method print is called&&&}int AboutConst::GetX(){}int AboutConst::GetY(){}void AboutConst::UseFriend(int i){ af.m = cout&&&using the friend class&&& cout&&&使用友元类,就可以通过对象,注意一定要通过友元类的对象,访问友元类中的所有成员&&& cout&&&for example, let print class AboutFriend's m through an AboutFriend object:&&&af.m&&;}//const double pi(3.1415926);int main(){ cout&&&使用构造函数&&& AboutConst ac1(2,32); AboutConst const ac3(50,20); cout&&&使用拷贝构造函数&&& AboutConst ac2(ac1); ac1.Print(); ac2.Print(); ac3.Print() ; OutPut(ac1); ac1.UseFriend(3); //cout&&&dd&&& //cout&&sin(pi)&& //cout&&cos(pi)&&& &&&tan(pi)&&return 0;}vs2005编译结果:1&------ 已启动生成: 项目: DD, 配置: Debug Win32 ------1&正在编译...1&tt.cpp1&.\tt.cpp(29) : error C2512: “AboutFriend”: 没有合适的默认构造函数可用1&.\tt.cpp(54) : error C2512: “AboutFriend”: 没有合适的默认构造函数可用1&.\tt.cpp(62) : error C2512: “AboutFriend”: 没有合适的默认构造函数可用1&生成日志保存在“file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\DD\DD\Debug\BuildLog.htm”1&DD - 3 个错误,0 个警告========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
我来帮他解答
其他类似问题
构造函数的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁c++ 入门求指导错误error C2512: “Person”: 没有合适的默认构造函数可用_百度知道
c++ 入门求指导错误error C2512: “Person”: 没有合适的默认构造函数可用
这是Person.h#pragma onceclass Person{public: Person(char*,int); int Person::getHeight(Person); char* Person::getName(Person);private: char* };这是Person.c#include &stdafx.h&#include &Person.h&Person::Person(char* name,int height){ Person::name= Person::height=}这是Student.h
Student继承了Person#pragma once#include &person.h&class Student : public Person{public: Student(void); Student(char *,int ,int ); ~Student(void);private: char *
};这是Student.cpp#include &StdAfx.h&#include &Student.h&Student::Student(char *name,int grade,int height){
//就是这个地方出现了这个错误,求解答啊 Student::grade= Student::height= Student::name=}Student::~Student(void){}
提问者采纳
Person.h:#pragma&onceclass&Person{public:Person();&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//添加了一个默认构造函数Person(char*,int);&&&&&&&&&&&&&&&&&&&&&&&&//这里缺少默认构造函数 int&Person::getHeight(Person); char*&Person::getName(Person);private: char*& int&};这是Person.c#include&&stdafx.h&#include&&Person.h&Person::Person(){&&&&//请自行添加初始化代码}Person::Person(char*&name,int&height){ Person::name= Person::height=}这是Student.h&&&Student继承了Person#pragma&once#include&&person.h&class&Student&: public&Person{public: Student(void); Student(char&*,int&,int&); ~Student(void);private: char&* int& int&};这是Student.cpp#include&&StdAfx.h&#include&&Student.h&Student::Student(char&*name,int&grade,int&height){&&//就是这个地方出现了这个错误,求解答啊//Student的基类Person缺少默认构造函数 Student::grade= Student::height= Student::name=}Student::~Student(void){}如果满意,欢迎采纳我的解答,谢谢如有疑问,欢迎追问
为什么需要这样的构造函数啊,有什么意义啊?我刚从JAVA转过来各种不适应
C++比Java严格,但也比Java自由度大。C++的类,必须有默认构造函数,带参数的构造函数不是必须的,根据需要添加,如果将默认构造函数添加参数改成带参数的构造函数,编译器由于找不到默认构造函数而报错。
提问者评价
其他类似问题
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁在类里定义了一个构造函数。但是没有定义默认构造函数,当要用到默认构造函数的时候会发生什么?
[问题点数:20分,结帖人t_jl1979]
在类里定义了一个构造函数。但是没有定义默认构造函数,当要用到默认构造函数的时候会发生什么?
[问题点数:20分,结帖人t_jl1979]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
2009年7月 总版技术专家分月排行榜第二2009年3月 总版技术专家分月排行榜第二2009年1月 总版技术专家分月排行榜第二2005年7月 总版技术专家分月排行榜第二2005年5月 总版技术专家分月排行榜第二2005年3月 总版技术专家分月排行榜第二
2009年6月 总版技术专家分月排行榜第三2009年2月 总版技术专家分月排行榜第三2005年4月 总版技术专家分月排行榜第三2005年1月 总版技术专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。

我要回帖

更多关于 复制构造函数 的文章

 

随机推荐