错误:对(构造函数)C ++的调用不匹配

问题描述 投票:0回答:1

我使用一个简单的构造函数,尝试调用默认构造函数时出现错误。如果im只是在不使用var Document *的def的情况下调用它,则d = NULL; d =新文档[n];我没有错误。但它看起来像文档d; d(数据);但是我需要像dindex这样的文档数组;请帮忙!

#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <conio.h>
#include <ctime>
#include <string.h>
using namespace std;
time_t now = time(0);
class Document{
    char *denumirea;
    char *tema;
    char *autor;
    int pages;
    char *dt; 
    public:
    Document(char* den, char* tem,char* aut,int pag)
    {
        denumirea = new char[strlen(den)+1];
        tema = new char[strlen(tem)+1];
        autor = new char[strlen(aut)+1];
        strcpy(denumirea,den);
        strcpy(tema,tem);
        strcpy(autor,aut);
        dt = ctime(&now);
        pages = pag;
    }   
    ~Document(){
    delete[] denumirea;
    delete[] tema;
    delete[] autor;
    delete[] dt;
    }
    Document(const Document& d)
    {
        denumirea = new char[strlen(d.denumirea)+1];
        tema = new char[strlen(d.tema)+1];
        autor = new char[strlen(d.autor)+1];
        dt = new char[strlen(d.dt)+1];
        strcpy(denumirea,d.denumirea);
        strcpy(tema,d.tema);
        strcpy(autor,d.autor);
        strcpy(dt,d.dt);
        pages = d.pages;
    }
    Document()
    {
        denumirea = new char[15];
        tema = new char[15];
        autor = new char[15];
        dt = new char[20];
        strcpy(denumirea,"Fara denumire");
        strcpy(tema,"Fara tema");
        strcpy(autor,"Fara autor");
        dt = ctime(&now);
        pages = 0;
    }
    void show()
    {
        cout<<"Denumirea: "<<denumirea<<"|Tema: "<<tema<<"|Autor :"<<autor<<"|Pagini: "<<pages<<endl<<"|Timpul: "<<dt<<endl;
    }
    void modif()
    {
        char* den;
        char* tem;
        char* aut;
        int pag;
        cout<<"Denumirea:"<<endl;
        cin>>den;
        cout<<"Tema:"<<endl;
        cin>>tem;
        cout<<"Autor:"<<endl;
        cin>>aut;
        cout<<"Pagini:"<<endl;
        cin>>pag;
        strcpy(denumirea,den);
        strcpy(tema,tem);
        strcpy(autor,aut);
        dt = ctime(&now);
        pages = pag;
    }
};

int main()
{
    int n,optiune;
    Document* d = NULL;
    d = new Document[n];
    char den[15],tem[15],aut[15],dt[20];
    int pag;

    while(1)
    {
        cout << "Meniul Principal:" << endl;
        cout << "1. Introduce document" << endl;
        cout << "2. Modifica document" << endl;
        cout << "3. Afiseaza document" << endl;
        cout << "4. Exit" << endl;
        cin >>optiune;
        switch(optiune)
        {
            default:{cout << "Error" << endl; getch() ; system("cls");break;}
            case 1:
                {
                    cout<<"Cate documente doriti sa introduceti: ";
                    cin>>n;
                    for(int i=0;i < n; i++)
                    {
                        cout<<"Denumirea:"<<endl;
                        cin>>den;
                        cout<<"Tema:"<<endl;
                        cin>>tem;
                        cout<<"Autor:"<<endl;
                        cin>>aut;
                        cout<<"Pagini:"<<endl;
                        cin>>pag;
                        d[i](den,tem,aut,pag);              
                    }
                }
        }
    }

}

在线获取错误:

d[i](den,tem,aut,pag);  

Error message Photo请我需要快速修复它((((

c++
1个回答
0
投票
d[i] = Document(den,tem,aut,pag)
© www.soinside.com 2019 - 2024. All rights reserved.