01/10/2018, 13:42
Lỗi trình biên dịch c3867 khi luyện tập tính đa hình
Lỗi trình biên dịch c3867 khi luyện tập tính đa hình . Lỗi nằm ở đoạn ds[i].output; dòng 146
// thuvien.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class docgia
{
protected:
string hoten;
string ngaylapthe;
int sthl;
public:
virtual void input();
virtual void output();
docgia();
~docgia();
private:
};
void docgia::input()
{
fflush(stdin);
cout << "Nhap ten doc gia: ";
getline(cin, hoten);
fflush(stdin);
cout << "Ngay lap the (dd/mm/yy): ";
getline(cin, ngaylapthe);
cout << "So thang hieu luc: ";
cin >> sthl;
}
void docgia::output()
{
cout << "Ho va ten: " << hoten << endl;
cout << "Ngay lap the: " << ngaylapthe << endl;
cout << "So thang hieu luc: " << sthl << endl;
}
docgia::docgia()
{
}
docgia::~docgia()
{
}
class treem : public docgia
{
public:
void input();
void output();
private:
int sotuoi;
string ndd;
};
void treem::input()
{
docgia::input();
cout << "Nhap so tuoi: ";
cin >> sotuoi;
cout << "Nhap ho ten nguoi dai dien: ";
cin.ignore(32767, '
');
getline(cin, ndd);
}
void treem::output()
{
docgia::output();
cout << "So tuoi: " << sotuoi << endl;
cout << "Ho ten nguoi dai dien: " << ndd << endl;
}
class nguoilon : public docgia
{
public:
void input()
{
docgia::input();
cin.ignore(32767, '
');
cout << "Nhap so cmdd: ";
getline(cin, cmdd);
}
void output()
{
docgia::output();
cout << "So chung minh nhan dan: " << cmdd << endl;
}
private:
string cmdd;
};
class thuvien
{
public:
void input();
void output();
private:
vector<docgia> ds;
};
void thuvien::input()
{
cout << " ==========================Hay chon doi tuong ban muon nhap===========" << endl;
cout << " 1. De nhap thong tin doi tuong tre em " << endl;
cout << " 2. De nhap thong tin doi tuong nguoi lon" << endl;
cout << "Nhap bat ky so khac de thoat chuong trinh" << endl;
int sl;
do
{
cout << "Lua chon cua ban la: ";
cin >> sl;
docgia *x;
if (sl == 1)
{
cout << "Nhap thong tin cua doi tuong tre em" << endl;
x = new treem;
x->input();
ds.push_back(*x);
}
if (sl == 2)
{
cout << "Nhap thong tin doi tuong nguoi lon" << endl;
x = new nguoilon;
x->input();
ds.push_back(*x);
}
} while (sl == 1 || sl == 2);
}
void thuvien::output()
{
cout << "====================Thong tin doc gia======================= " << endl;
for (int i = 0; i < ds.size(); i++)
{
cout << "thong tin doc gia thu " << i + 1 << endl;
ds[i].output;
}
}
int main()
{
thuvien *x = new thuvien;
x->input();
x->output();
return 0;
}
Bài liên quan
Thiếu dấu đóng mở ngoặc
()
Tks thánh nha em ức cả ngày hôm nay chỉ vì cái lỗi cơ bản thế này. Chắc phải siêng bài tập hơn mới được