为了账号安全,请及时绑定邮箱和手机立即绑定

C++改错怎么改?

C++改错怎么改?

C C# C++
灬elliott 2016-06-25 14:02:25
一、实验目的1.理解多重派生的定义;2.理解多重派生中构造函数与析构函数的调用顺序;3.理解多重派生中虚拟基类的作用;二、实验内容2.1练习(一):1.理解下面的程序,并在VC++6.0下运行查看结果,回答程序后面的问题。class CBase1{public:CBase1(int a)  :a(a){  cout<<"base1 structure..."<<endl;}~CBase1(){  cout<<"base1 destructure..."<<endl;}void print(){  cout<<"a="<<a<<endl;}protected:int a;};class CBase2{public:CBase2(int b)  :b(b){  cout<<"base2 structure..."<<endl;}~CBase2(){  cout<<"base2 destructure..."<<endl;}void print(){  cout<<"b="<<b<<endl;}protected:int b;};class CDerive : public CBase1, public CBase2{public:CDerive(){  cout<<"derive structure..."<<endl;}~CDerive(){  cout<<"derive destructure..."<<endl;}void print(){  CBase1::print();  CBase2::print();  b1.print();  b2.print();  cout<<"c="<<c<<endl;}private:CBase1 b1;CBase2 b2;int c;};void main(){CDerive d;d.print();}问题一:改正以上程序中存在的错误,并分析该程序的输出结果。2.理解下面的程序,并在VC++6.0下运行查看结果,回答程序后面的问题。#include "iostream.h"class CBase{public:CBase(int a)  :a(a){}int a;};class CDerive1 : public CBase{public:CDerive1(int a)  :CBase(a){}};class CDerive2 : public CBase{public:CDerive2(int a)  :CBase(a){}};class CDerive : public CDerive1,public CDerive2{public:CDerive(int a,int b)  :CDerive1(a),CDerive2(b){}};void main(){CDerive d(1,2);cout<<d.a<<endl;}问题一:在不改变原有程序意图的前提下,改正以上程序,并使程序正确输出。
查看完整描述

4 回答

已采纳
?
惊回头

TA贡献12条经验 获得超4个赞

1>c:\users\administrator\desktop\bia\空\空\空.cpp(7): error C2065: “cout”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(7): error C2065: “endl”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(11): error C2065: “cout”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(11): error C2065: “endl”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(15): error C2065: “cout”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(15): error C2065: “endl”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(26): error C2065: “cout”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(26): error C2065: “endl”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(30): error C2065: “cout”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(30): error C2065: “endl”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(34): error C2065: “cout”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(34): error C2065: “endl”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(42): error C2512: “CBase1”: 没有合适的默认构造函数可用

1>c:\users\administrator\desktop\bia\空\空\空.cpp(42): error C2512: “CBase2”: 没有合适的默认构造函数可用

1>c:\users\administrator\desktop\bia\空\空\空.cpp(42): error C2512: “CBase1”: 没有合适的默认构造函数可用

1>c:\users\administrator\desktop\bia\空\空\空.cpp(42): error C2512: “CBase2”: 没有合适的默认构造函数可用

1>c:\users\administrator\desktop\bia\空\空\空.cpp(44): error C2065: “cout”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(44): error C2065: “endl”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(48): error C2065: “cout”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(48): error C2065: “endl”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(56): error C2065: “cout”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(56): error C2065: “endl”: 未声明的标识符

1>c:\users\administrator\desktop\bia\空\空\空.cpp(70): error C2143: 语法错误 : 缺少“;”(在“常量”的前面)

1>c:\users\administrator\desktop\bia\空\空\空.cpp(70): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

1>c:\users\administrator\desktop\bia\空\空\空.cpp(71): fatal error C1083: 无法打开包括文件:“iostream.h”: No such file or directory


查看完整回答
1 反对 回复 2016-07-09
?
断桥丶晓风残月

TA贡献32条经验 获得超15个赞

编译器有提示吧?

查看完整回答
1 反对 回复 2016-06-27
?
奋斗的油菜

TA贡献4条经验 获得超6个赞

看看编译器,要自己找错误

查看完整回答
反对 回复 2016-07-08
?
jfhdibrbfjd

TA贡献163条经验 获得超40个赞

简单   自己作

查看完整回答
反对 回复 2016-06-27
  • 4 回答
  • 0 关注
  • 3870 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信