此代码将类A简单嵌套类B中,其代码如下:
#include "stdafx.h"
#include
using namespace std;
class A{
public:
A(){
English=100;
};
~A(){
delete []name;
};
void Name (char *p){
name=new char[strlen(p)+1];
strcpy(name,p);
};
public:
char *name;
int English;
};
class B {
private:
A a;
public:
void print(char *f){
         a.Name (f);
cout<<"Name: "<<a.name<<"\t"<<"English= "<<a.English<<endl;
};
};
int _tmain(int argc, _TCHAR* argv[])
{
B b;
b.print("跳动飞雪");
 
while (1);
return 0;
}

相关文章:

  • 2021-05-15
  • 2021-09-24
  • 2021-11-14
  • 2022-12-23
  • 2021-12-20
  • 2021-09-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-21
  • 2021-05-30
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
相关资源
相似解决方案