Ok I have all of my code written, but I am not sure about overloading the == and < operators. I keep getting an error that says no match for operator < in 's1<s3'
here is the code...I have tried addingbut that doesn't work either.Code:friend Song::operator==(const Song &s)
Code://song.h #ifndef SONG_H #define SONG_H #include <stdlib.h> #include <iostream> #include <ostream> #include <string> #include "BobCatPod.h" using namespace std; class Song { public: Song(); Song(string , string , int ); // constructor void setSize(int s); int getSize(); // access or void setTitle (string t); string getTitle(); void setArtist (string a); string getArtist(); void addSong (int); friend ostream& operator<<(ostream & os, const Song & s); private: string title; //dynamic allocation string artist; int size; }; #endifThanksCode:// poddriver.cpp //Adapted from Roger Priebe //CS2308 11/17/08 #include <stdlib.h> #include <iostream> #include "BobCatPod.h" #include "song.h" using namespace std; int main() { Song s1("Frank Sinatra", "My way", 14); Song s2("Beatles", "Act Naturally", 5); Song s3; BobCatPod p(256); BobCatPod q(512); BobCatPod r(25); cout << "pod p" << endl << p << endl; cout << "pod q, size 512 exceeds max, should be reset to 256 " << endl << q << endl; cout << "pod r, size should be 25 " << endl << r << endl; cout << "Song 1" << s1 << endl; cout << "Song 2" << s2 << endl; cout << "Song 3" << s3 << endl; s3.setArtist("Buck Owens"); s3.setTitle("Act Naturally"); s3.setSize(20); cout << "Song 3 updated " << s3 << endl; cout << "Artist 1 (Frank Sinatra) " << s1.getArtist() << endl; cout << "Title 2 (Act Naturally) " << s2.getTitle() << endl; // s1.setSize(7); // cout << "Size 1 (7) " << s1.getSize() << endl; //test relational operators if (s1 < s3 ) cout << endl << "s1 < s3" << endl; else cout << endl << "s1 >= s3" << endl; if (s1 == s2) cout << endl << "s1 == s2" << endl; else cout << endl << "s1 != s2" << endl; // test addnode cout << "add song 1, size 14 " << r.addSong(s1) << endl; cout << " memory left = " << r.getRemainingMemory() <<endl; cout << "add song 2, size 5 " << r.addSong(s2)<< endl; cout << " memory left = " << r.getRemainingMemory() << endl; cout << "add song 3, size 20 should fail " << r.addSong(s3) <<endl; cout << " memory left = " << r.getRemainingMemory() << endl; s3.setSize(2); cout << "Size 3 (2) " << s3.getSize() << endl; cout << "add song 3, size 2 should succeed " << r.addSong(s3) << " memory left = " << r.getRemainingMemory() << endl; // test output cout << r << endl; //test delete r.removeSong(s1); cout << r << endl; r.removeSong(s3); cout << r << endl; cout << "Total Memory = "<< r.getTotalMemory() << endl; return 0; }



LinkBack URL
About LinkBacks


