1. Trang chủ
  2. » Công Nghệ Thông Tin

LẬP TRÌNH C nâng cao - bài 3 - nhắc lại về lớp part 2

6 6 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

BÀI 3: NHẮC LẠI VỀ LỚP Cơ bản về lớp Chúng ta sẽ được nhắc lại cách viết các hàm cơ bản để khởi tạo lớp và các hàm cơ bản liên quan.

LẬP TRÌNH C/C++ NÂNG CAO Yêu cầu trước đọc: học xong Lập trình C/C++ BÀI 3: NHẮC LẠI VỀ LỚP Cơ lớp CODE class Date{ int day; public: Date(int,int a=1); int month; void setDay(int); void output(); }; int main(){ Date d(6); d.month=3; d.setDate(25); d.output(); return 0; } Date::Date(int day,int month){ this->day=day; this->month=month; } void Date::setDay(int day){ this->day=day; } void Date::output(){ cout>d.day; ins>>d.month; ins.get(); //phải xóa đệm return ins; } ostream& operatorspecial=special; } Date::Date(const Date& d){ this->day=d.day;this->month=d.month; this->special=new char[strlen(d.special)+1]; / /c? ??p... khởi tạo chép (copy constructor CODE class Date{ public: int day;int month;char *special; Date(int,int,char*); Date(const Date&); ~Date(){ delete [] special; //bởi c? ??p phát nhớ cho } }; Date::Date(int... s1;s1.id =2; Student s2;s2.id =3; cout

Ngày đăng: 20/05/2021, 11:42

Xem thêm: