Answer the question
In order to leave comments, you need to log in
Why isn't the assignment operator overloaded (the program doesn't even run)?
main.cpp:
#define __CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include "classic.h"
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#include <iostream>
void bravo(const cd& disk);
int main()
{
cd c1("b\0", "c\0", 14, 35.5);
classic c2 = classic("p\0", "c\0", "a\0", "p\0", 2, 57.17);
cd* pcd = &c1;
c1.report();
c2.report();
pcd->report();
pcd = &c2;
pcd->report();
bravo(c1);
bravo(c2);
classic copy;
copy = c2;
//copy.report();
return 0;
}
void bravo(const cd& disk) {
disk.report();
}
#ifndef classic
#include "cd.h"
class classic :public cd {
private:
char cursong[20];
char curperform[50];
//char* cursong;
public:
classic(const char* s1, const char* s2,const char *s3, const char * s4,int n, double x);
virtual void report()const;
classic();
classic& operator=(const classic& d);
};
#endif // !classic
#define _CRT_SECURE_NO_WARNINGS
#include "classic.h"
#include <string.h>
#include <iostream>
using std::cout;
classic::classic(const char* s1, const char* s2, const char* s3, const char* s4, int n, double x):cd(s1,s2,n,x) {
strcpy(curperform, s4);
strcpy(cursong, s3);
}
void classic::report() const{
cd::report();
for (auto& x : cursong) {
if (x == '\0') break; cout << x;
}
cout << "\n";
for (auto& x : curperform) {
if (x == '\0') break;
cout << x;
}
cout << "\n";
}
classic& classic::operator=(const classic& d) {
if (this == &d) return *this;
strcpy(cursong, d.cursong);
strcpy(curperform, d.curperform);
cd::operator=(d);
return *this;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question