[英]Expression _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) Error
[英]Error - _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
我有一個錯誤“ _BLOCK_TYPE_IS_VALID(pHead-> nBlockUse)”,並且不知道該怎么辦。
person.h
#ifndef _person_H
#define _person_H
class person
{
private:
char * name;
int * age;
char * address;
public:
void get_info(void);
void show_info(void);
person();
~person();
};
#endif _person_H
person.cpp
#include "stdafx.h"
#include <stdlib.h>
#include <string>
#include "person.h"
#include <iostream>
using namespace std;
person::person()
{
this->name = new char[50];
this->age = new int;
this->address = new char[50];
}
person::~person()
{
delete this->name;
delete this->age;
delete this->address;
}
void person::get_info()
{
cout << "write name and surname:" << endl;
cin >> name;
cout << endl;
cout << "write age:" << endl;
cin >> *(age);
cout << endl;
cout << "write address:" << endl;
cin >> address;
cout << endl;
}
void person::show_info()
{
cout << "Name and surname:" << name << endl;
cout << "Age:" << *age << endl;
cout << "Address:" << address << endl;
}
main.cpp中
#include "stdafx.h"
#include "person.h"
int _tmain(int argc, _TCHAR* argv[])
{
int i;
person * newperson = new person[5];
for (i = 0; i<5; i++){
newperson[i].get_info();
}
for (i = 0; i<5; i++){
newperson[i].show_info();
}
delete newperson;
return 0;
}
您能幫我解決這個錯誤嗎? 我也想知道,如何將兩個單詞(名稱和姓氏)寫到變量“名稱”中? 使用“ cin >>名稱”,我只能寫一個字...
析構函數必須定義為
person::~person()
{
delete [] this->name;
delete this->age;
delete [] this->address;
}
而這個statemenet
delete newperson;
必須替換此語句
delete [] newperson;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.