C++中的A*p是什么意思?
#include<iostream>usingnamespacestd;classA{public:A(){cout<<"A";}//~A(){cout<<"~A";}}...
#include <iostream>
using namespace std;
class A
{
public:
A(){cout<<"A";}
//~A(){cout<<"~A";}
};
class B:public A
{
A*p;
public:
B(){cout<<"B";p=new A();}
//~B(){cout<<"~B";delete p;}
};
int main()
{
B obj;
system("pause");
return 0;
} 展开
using namespace std;
class A
{
public:
A(){cout<<"A";}
//~A(){cout<<"~A";}
};
class B:public A
{
A*p;
public:
B(){cout<<"B";p=new A();}
//~B(){cout<<"~B";delete p;}
};
int main()
{
B obj;
system("pause");
return 0;
} 展开
3个回答
展开全部
#include <iostream>
using namespace std;
class A
{
public:
A(){cout<<"A";}
//~A(){cout<<"~A";}
};
class B:public A
{
A*p; // 创建类A的一个指针变量。这个指针是private的
public:
B(){cout<<"B";p=new A();}
//~B(){cout<<"~B";delete p;}
};
int main()
{
B obj;
system("pause");
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询