- 论坛徽章:
- 0
|
C++中delete?
//filename:first.cpp
// A first look at C++ program
#include <iostream.h>;
#include <ctype.h>;
class animalType
{
char breed[40]; //array of characters
public:
void getBreed(void) //Get the animal's breed name
{
cout<<"What is the breed?";
cin>;>;breed; //User types the name
}
void prBreed(void)
{
cout<<"The animal'breed is "<<breed<<'\n';
}
};
//Actral program starts here
void main(void)
{
animalType *animals[25]; //C++ doesn't need class keyboard
float *newf=new float;
float testf;
int num = 0;
char ans;
do
{ animals[num]=new animalType; //Allocate space
animals[num++]->;getBreed();
cout<<"Do you want to enter another animal(Y/N)?";
cin>;>;ans;
}
while (toupper(ans)!='N');
// Now,print each of the breeds
for (int ctr=0;ctr<num;ctr++)
{ animals[ctr]->;prBreed(); }
}
如果我想释放animals,怎么写程序? |
|