调试断言失败 - 表达式:_CrtlsValidHeapPointer(块)

时间:2015-09-15 16:56:37

标签: c++

嗨,我是新来的,很抱歉,如果我有任何正式的错误。

我的库程序有问题,它有两个类:Book和Person。 我写了_customer = customer后出现错误;在Book construcor。

我如何解释错误?我做错了什么?

人类

class Person{

private:
    char* _name;
    int _id;
    static int personCounter;

public:
    void setName(char* name);
    void setId(int id);
    char* getName();
    char* getName() const;
    int getId();
    int getId()const;
    void showData();
    Person();
    Person(int id, char* name);
    Person(const Person &tempPerson);
    ~Person();

};

人员复制构造函数

Person::Person(const Person &tempPerson) {
    _id = tempPerson.getId();
    _name = new char[strlen(tempPerson.getName())];
    strcpy(_name, tempPerson.getName());
    personCounter--;
}

预订课程

class Book{

private:
    char* _title;
    char* _author;
    char* _genre;
    bool _borrowed;
    Person _customer;
    static int counter;

public:
    void setTitle(char* title);
    void setAuthor(char* author);
    void setGenre(char* genre);
    void setStatus(bool borrowed);
    void setPerson(Person customer);

    char* getTitle();
    char* getAuthor();
    char* getGenre();
    bool getStatus();
    Person getPerson();
    void showData();

    Book();
    Book(char* title, char* author, char* genre, bool borrowed, const Person &customer);

    ~Book();

};

图书构造函数

Book::Book(char* title, char* author, char* genre, bool borrowed,const  Person &customer){
    counter++;



    _title = new char[strlen(title) + 1];
    strcpy(_title,title);

    _author = new char[strlen(author) + 1];
    strcpy(_author, author);

    _genre = new char[strlen(genre) + 1];
    strcpy(_genre, genre);

    _borrowed = borrowed;

    _customer = customer;

}

1 个答案:

答案 0 :(得分:0)

解决了它。我没有" ="的覆盖功能操作