no matching function for call to 'DB::add_rec(const char [9], char, int, float)'
#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <string>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <windows.h>
using namespace std;
class church {
char *name;
char school;
unsigned int count;
unsigned short square;
friend ostream & operator<<(ostream &stream, church &o1);
friend istream & operator>>(istream &stream, church &o1);
friend void shapka(void);
friend void linebuild(void);
public:
church() { count=0; square=0;}
church(char *a, char b, int c, float d);
void set(char *a,char ,int ,float );
void get(char *a, char &b, int &c, float &d);
void show(void);
char ret_name() {return *name;}
};
void shapka(void)
{
cout<<"_______________________________________________________________\n";
cout<<"| Буддистские монастыри Японии периода Нара |\n";
cout<<"|-------------------------------------------------------------|\n";
cout<<"| Название | Школа | Количество монахов | Площадь земли(га) |\n";
cout<<"|-------------------------------------------------------------|\n";
}
void linebuild(void) {
cout<<"\n|-------------------------------------------------------------|\n";
}
class DB {
char title[30];
church *rows[12];
int col;
int sorted;
public:
DB(char *q) {strcpy(title,q); col=0; sorted=0;}
~DB(){if (col) for (int i=0; i<col; i++) delete rows[i];}
void add_rec(char *a, char &b, int &c, float &d);
void del_rec();
void sort_DB();
friend ostream & operator<<(ostream &stream, DB &temp);
};
void DB::add_rec(char *a, char &b, int &c, float &d) {
if (col>=12) return;
else col++;
rows[col-1] = new church(a,b,c,d);
sorted=0;
}
void DB::del_rec() {
if (col<=0) return;
delete rows[col-1];
col--;
}
void DB::sort_DB() {
char s1;
char s2;
if (col<2) return;
church *temp;
for (int i=0; i<col; i++)
for (int j=i+1; j<col; j++) {
s1 = rows[i]->ret_name();
s2 = rows[j]->ret_name();
if (s1 > s2) {
temp=rows[i];
rows[i]=rows[j];
rows[j]=temp;
}
}
sorted=1;
}
ostream & operator<<(ostream &stream, DB &o1) {
stream<<o1.title<<endl;
if (o1.sorted==0) stream<<"Таблица не отсортирована.\n";
else stream<<"Таблица отсортирована.\n";
shapka();
if (!o1.col) stream<<"Таблица пуста.";
else {
for (int i=0; i<o1.col; i++) {
stream<<*o1.rows[i];
}
}
return stream;
}
ostream & operator<<(ostream &stream, church &o1) {
stream<<"|"<<setw(10)<<o1.name<<" | ";
stream<<setw(5)<<o1.school<<"|";
stream<<setw(18)<<o1.count<<" |";
stream<<setw(17)<<o1.square<<" |";
cout<<endl;
//linebuild();
return stream;
}
church::church(char *a, char b , int c, float d) {
name=new char [strlen(a)+1];
strcpy(name,a);
school=b;
count=c;
square=d;
}
void church::set(char *a,char b,int c,float d) {
for (int i=0; i<10; i++){
name[i]=a[i];
}
school=b;
count=c;
square=d;
}
void church::show(void) {
cout<<name<<" ";
cout<<school<<" ";
cout<<count<<" ";
cout<<square<<" ";
}
void church::get( char * a, char &b, int &c, float &d)
{
strcpy(a,name);
b=school;
c=count;
d=square;
}
//void linebuild(void) {
// cout<<"\n|-------------------------------------------------------------|\n";
//}
int main(void) {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
char *n;
char t;
int s;
float h;
short i;
short q,q1;
//clrscr();
DB *tmp = new DB("\nБАЗА ДАННЫХ ¦1\n");
for (int a=0; !a;){
//clrscr();
cout <<"1. Добавить запись\n" ;
cout <<"2. Удалить запись\n";
cout <<"3. Сортировать базу\n";
cout <<"4. Вывести базу\n";
cout <<"5. Выход\n";
cout <<"> ";
int p;
cin>>p;
switch(p) {
case 1: {
cout<<"Наименование, Тип, Посевная площадь, Урожайность \n";
//cin>>n; // Закомментированные строки отвечают за чтение значений
//cin>>t; // переменных с клавиатуры и записи их в поля объекта.
//cin>>s; // Для удобства работы используется инициализация через
//cin>>h; // конструктор 3-х объектов.
//tmp->add_rec( n, t, s, h );
tmp->add_rec("Тотайдзи",'Т',220, 368.8f);
tmp->add_rec("Якусидзи",'С',50, 12.7f);
tmp->add_rec("Дайандзи",'Д',10, 12.2f);
break;
}
case 2: {
tmp->del_rec();
break;
}
case 3: {
tmp->sort_DB();
break;
}
case 4: {
cout<<*tmp;
cout<<"\nНажмите клавишу для продолжения...";
getch();
break;
}
case 5: {
a=1;
break;
}
default :{
cout << "Неверный вызов";
getch();
break;
}
}
}
return 0;
}
const char* вот так должно быть или нет ?
Обязательно нужно решить задачу через char. string не нужно применять! Спасибо ))
Ответы (2 шт):
Автор решения: Harry
→ Ссылка
А посмотреть внимательно?
void add_rec(char *a, char &b, int &c, float &d);
А вызываете как?
char *n;
char t;
unsigned int s;
float h;
....
tmp->add_rec( n, t, s, h );
Ну и как быть компилятору, если третьим параметром должен быть int&, а вы ему подсовываете unsigned int?
А, вы исправили код... ну что ж, тут
tmp->add_rec("Тотайдзи",'Т',220, 368.8f);
все еще хуже, потому что вы передали значения (rvalue), которые ссылками быть никак не могут, а первым - строковый литерал.
В С++ строковый литерал - это константный массив, каковой может приводиться к const char*, но не char*, так что и выше, в add_rec, и здесь
DB("\nБАЗА ДАННЫХ ¦1\n");
у вас сплошные проблемы...
Автор решения: Медербек Канатбеков
→ Ссылка
char *n = new char[12];
изменил строку на это и закомментировал
`tmp->add_rec("Тотайдзи",'Т',220, 368.8f);
tmp->add_rec("Якусидзи",'С',50, 12.7f);
tmp->add_rec("Дайандзи",'Д',10, 12.2f)`
Теперь код работает