Code này lỗi ở hàm hủy em sửa hoài không được, mọi người hướng dẫn em cách sửa với ạ
#include <iostream>
#include <conio.h>
using namespace std;
class A {
private:
char *m_s;
public:
A() {
m_s = _strdup("default");
}
A(char *s) {
m_s = s;
}
virtual void prepare() {
cout << "A ";
}
void display() {
prepare();
cout << m_s << endl;
}
friend ostream& operator<<(ostream &os, const A &str) {
puts(str.m_s);
return os;
}
friend istream &operator >> (istream &is, A &str) {
cout << "Nhap chuoi: ";
_flushall();
gets_s(str.m_s, 100);
return is;
}
virtual ~A() {
cout << "Bien m_s da dc xoa" << endl;
delete []m_s;
}
};
class B : public A {
public:
B() {};
B(char *s) : A(s) {
}
B(const B &b) {
}
void prepare() {
cout << "B ";
}
~B() {
cout << " Huy " << endl;
}
};
void foo(A *obj1, A obj2) {
obj1->display();
obj2.display();
}
void main() {
B obj1("text");
A *obj2 = new B(obj1);
foo(&obj1, *obj2);
delete obj2;
/*A temp;
cin >> temp;
cout << temp;*/
_getch();
}
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?