新建
上传
首页
助手
最?/div>
资料?/div>
工具

 

实验?/p>

 

继承与派?/p>

 

?/p>

实验目的

?/p>

 

1

?/p>

 

掌握继承的概念?/p>

 

2

?/p>

 

理解派生类与基类的关系?/p>

 

3

?/p>

 

理解不同的继承类型?/p>

 

4

?/p>

 

掌握继承下的构造函数和析构函数?/p>

 

5

?/p>

 

掌握单继承和多继承使用方法?/p>

 

6

?/p>

 

理解静态成员?/p>

 

?/p>

实验内容

?/p>

 

 

1

、上机分析下面程序,理解继承下构造函数和析构函数的执行顺序?/p>

 

#include <iostream> 

using namespace std; 

class A 

{ 

public: 

A() 

{ 

cout<<"Constructor1_A"<< x << endl; 

} 

A( int m ) : x( m ) 

{ 

cout<<"Constructor2_A"<< x << endl; 

} 

~A() 

{ 

cout<<"Destructor_A"<< x << endl; 

} 

private: 

int x; 

}; 

class B : public A 

{ 

public: 

B() 

{ 

cout<<"Constructor1_B"<< y << endl; 

} 

B( int m, int n, int l ) : A( m ), a( n ), y( l ) 

{ 

cout<<"Constructor2_B"<< y <<endl; 

} 

~B() 

{ 

cout<<"Destructor_B"<< y << endl; 

} 

private: 

A a; 

int y; 

}; 

int main() 

{ 

Ͼλ
新建
上传
首页
助手
最?/div>
资料?/div>
工具

 

实验?/p>

 

继承与派?/p>

 

?/p>

实验目的

?/p>

 

1

?/p>

 

掌握继承的概念?/p>

 

2

?/p>

 

理解派生类与基类的关系?/p>

 

3

?/p>

 

理解不同的继承类型?/p>

 

4

?/p>

 

掌握继承下的构造函数和析构函数?/p>

 

5

?/p>

 

掌握单继承和多继承使用方法?/p>

 

6

?/p>

 

理解静态成员?/p>

 

?/p>

实验内容

?/p>

 

 

1

、上机分析下面程序,理解继承下构造函数和析构函数的执行顺序?/p>

 

#include <iostream> 

using namespace std; 

class A 

{ 

public: 

A() 

{ 

cout<<"Constructor1_A"<< x << endl; 

} 

A( int m ) : x( m ) 

{ 

cout<<"Constructor2_A"<< x << endl; 

} 

~A() 

{ 

cout<<"Destructor_A"<< x << endl; 

} 

private: 

int x; 

}; 

class B : public A 

{ 

public: 

B() 

{ 

cout<<"Constructor1_B"<< y << endl; 

} 

B( int m, int n, int l ) : A( m ), a( n ), y( l ) 

{ 

cout<<"Constructor2_B"<< y <<endl; 

} 

~B() 

{ 

cout<<"Destructor_B"<< y << endl; 

} 

private: 

A a; 

int y; 

}; 

int main() 

{ 

">
新建
上传
首页
助手
最?/div>
资料?/div>
工具

 

实验?/p>

 

继承与派?/p>

 

?/p>

实验目的

?/p>

 

1

?/p>

 

掌握继承的概念?/p>

 

2

?/p>

 

理解派生类与基类的关系?/p>

 

3

?/p>

 

理解不同的继承类型?/p>

 

4

?/p>

 

掌握继承下的构造函数和析构函数?/p>

 

5

?/p>

 

掌握单继承和多继承使用方法?/p>

 

6

?/p>

 

理解静态成员?/p>

 

?/p>

实验内容

?/p>

 

 

1

、上机分析下面程序,理解继承下构造函数和析构函数的执行顺序?/p>

 

#include <iostream> 

using namespace std; 

class A 

{ 

public: 

A() 

{ 

cout<<"Constructor1_A"<< x << endl; 

} 

A( int m ) : x( m ) 

{ 

cout<<"Constructor2_A"<< x << endl; 

} 

~A() 

{ 

cout<<"Destructor_A"<< x << endl; 

} 

private: 

int x; 

}; 

class B : public A 

{ 

public: 

B() 

{ 

cout<<"Constructor1_B"<< y << endl; 

} 

B( int m, int n, int l ) : A( m ), a( n ), y( l ) 

{ 

cout<<"Constructor2_B"<< y <<endl; 

} 

~B() 

{ 

cout<<"Destructor_B"<< y << endl; 

} 

private: 

A a; 

int y; 

}; 

int main() 

{ 

Ͼλ">
Ͼλ
Ŀ

816306411_5_实验?继承与派?- 百度文库
新建
上传
首页
助手
最?/div>
资料?/div>
工具

 

实验?/p>

 

继承与派?/p>

 

?/p>

实验目的

?/p>

 

1

?/p>

 

掌握继承的概念?/p>

 

2

?/p>

 

理解派生类与基类的关系?/p>

 

3

?/p>

 

理解不同的继承类型?/p>

 

4

?/p>

 

掌握继承下的构造函数和析构函数?/p>

 

5

?/p>

 

掌握单继承和多继承使用方法?/p>

 

6

?/p>

 

理解静态成员?/p>

 

?/p>

实验内容

?/p>

 

 

1

、上机分析下面程序,理解继承下构造函数和析构函数的执行顺序?/p>

 

#include <iostream> 

using namespace std; 

class A 

{ 

public: 

A() 

{ 

cout<<"Constructor1_A"<< x << endl; 

} 

A( int m ) : x( m ) 

{ 

cout<<"Constructor2_A"<< x << endl; 

} 

~A() 

{ 

cout<<"Destructor_A"<< x << endl; 

} 

private: 

int x; 

}; 

class B : public A 

{ 

public: 

B() 

{ 

cout<<"Constructor1_B"<< y << endl; 

} 

B( int m, int n, int l ) : A( m ), a( n ), y( l ) 

{ 

cout<<"Constructor2_B"<< y <<endl; 

} 

~B() 

{ 

cout<<"Destructor_B"<< y << endl; 

} 

private: 

A a; 

int y; 

}; 

int main() 

{ 



ļ׺.doc޸Ϊ.docĶ

  • пҤԱλ׼
  • ֤ȯͶʷ - ۾÷ - 2009
  • Ϣơˢӹߡѧ
  • ѧѧ
  • 2019עһʦ蹤ĿϰD ()
  • ʤԿסҵԾD
  • 2018-2024йҵгչͶսǰԤⱨ
  • ҵѧ()[13ҳ]
  • ʦԱǿȽԵ˼-ĵ
  • ¸߿ֽ⣺ר04ϵˮ()ϰ()

վ

԰ Ͼλ
ϵͷ779662525#qq.com(#滻Ϊ@)