-2

我正在将此课程扩展到一本有声读物:

#include "Book.h"
using namespace std;
Book::Book():year(0), title(NULL), authors(NULL){}
Book::Book(vector<string>* bookauthors,string booktitle, int bookyear ){
    authors = bookauthors;
    title = booktitle;
    year = bookyear;
}
Book::Book(const Book& aBook){
    authors = aBook.authors;
    title = aBook.title;
    year = aBook.year;
}
Book::~Book(){
    //delete authors;
    //delete &title;
    //delete &year;
}
bool Book::operator==(const Book &aBook){
    if(getYear() == aBook.getYear() && getTitle() == aBook.getTitle())
        return true;
    else return false;
}
bool Book::operator != (const Book &aBook){
    if(getYear() != aBook.getYear() && getTitle() != aBook.getTitle())
        return true;
    else return false;
}
Book& Book::operator =(const Book& rhs){
    if(this != &rhs){
        authors = rhs.authors;
        title = rhs.title;
        year = rhs.year;
    }
    return *this;
}
void Book::update(int newyear){
    year = newyear;
}
void Book::update(string newtitle){
    title = newtitle;    
}
void Book::update(vector<string>* newauthors){
    authors = newauthors;
}
/*void Book::getAuthors()const{
    for(int i = 0; i < authors->size(); i++){
        cout<<authors->at(i);
    }
}*/
std::ostream& operator <<(std::ostream& os, const Book& b){
    os<<b.getTitle()<<", "<<b.getYear();
    for(int i = 0; i < b.authors->size();i++){
        os<<",  "<<b.authors->at(i);
    }
    return os;
}

我不断收到这个有声读物课程的错误:

#include "AudioBook.h"
AudioBook::AudioBook():Book(),length(0){}
AudioBook::AudioBook(vector<string>* authors1, string title1, int year1, double length1){
    Book(authors1, title1, year1);
    length = length1;
}
AudioBook::AudioBook(const AudioBook& other):Book(other),length(other.length){}

AudioBook& AudioBook::operator =(const AudioBook& rhs){
    Book::operator =(rhs);
    length = rhs.length;
}
AudioBook::~AudioBook(){

}
bool AudioBook::operator !=(const AudioBook& aBook){
    Book::operator !=(aBook);
    if(length == aBook.length)
        return false;
    else
        return true;
}
void AudioBook::update(double newlength){
    length = newlength;
}
/*std::ostream& operator<<(ostream& os, const AudioBook& aBook){
    Book::operator<<(os, aBook);
    os<<"length: "<<aBook.getLength()<<;
}*/

这就是我得到的:libc++abi.dylib:终止调用抛出异常

我不确定它是否覆盖了运营商或什么?还有我怎么能覆盖操作符<

4

1 回答 1

0

AudioBook& AudioBook::operator =(const AudioBook& rhs)不见了return *this;

不确定这是否是原因。

于 2012-10-16T12:30:24.353 回答