Id 返回 1 个退出状态

Id returned 1 exit status

本文关键字:退出 状态 返回 Id      更新时间:2023-10-16

当我尝试编译它时弹出此错误(对不起,它是西班牙语)

#include <iostream>
#include <string>
using namespace std;
//////////////////////////////
// Contacto
class contacto
{
    private:
        string nombre;
        string apellido;
        string numTelf;
        string numCel;
        string correo;
        string ciudad;
        string pais;
        string grupo;
    public:
        contacto (string nom, string apel, string tel, string cel, string cor, string ciu, string pai, string grup)
        {
        nombre = nom;
        apellido = apel;
        numTelf = tel;
        numCel = cel;
        correo = cor;
        ciudad = ciu;
        pais = pai;
        grupo = grup;       
        }
        void getContacto (string nom, string apel)
        {
            
        }
};
class agenda
{
    private:
        contacto arreglo[40];
    public:
    agenda();
        void setContacto(int n)
        {
        }
};

int main ()
{
int op, N;
agenda agen;
    cout<<"N:";
    cin>>N;
    agen.setContacto(N);        
    
    
system("pause");
return 0;
}

我知道它与对象声明和议程类的构造函数有关,我试图删除它,但只是给了我其他错误,我只需要访问 agend.setContacto(N); 但它一直给我错误,并且由于 Agenda 类只有一个对象数组,我不知道如何制作一个有效的构造函数。

我把类留在这里,以便更容易看到:

班级联系人:

class contacto
{
    private:
        string nombre;
        string apellido;
        string numTelf;
        string numCel;
        string correo;
        string ciudad;
        string pais;
        string grupo;
    public:
        contacto (string nom, string apel, string tel, string cel, string cor, string ciu, string pai, string grup)
        {
            nombre = nom;
            apellido = apel;
            numTelf = tel;
            numCel = cel;
            correo = cor;
            ciudad = ciu;
            pais = pai;
            grupo = grup;
        }
        void setContacto (string nom, string apel, string tel, string cel, string cor, string ciu, string pai, string grup)
        {
            nombre = nom;
            apellido = apel;
            numTelf = tel;
            numCel = cel;
            correo = cor;
            ciudad = ciu;
            pais = pai;
            grupo = grup;           
        }
        void getContacto (string nom, string apel)
        {
            
        }
};

课程议程:

class agenda
{
    private:
        contacto arreglo[40];
    public:
    agenda();
        void setContacto(int n)
        {
};

编辑:弹出的错误是

[链接器错误] 未定义对"议程::议程()"的引用

LD 返回 1 个退出状态

EDIT2:contacto 类只需要一个空的构造函数,让 Agenda 类初始化数组

声明一个构造函数时,还应声明默认(空)构造函数。

class contacto中,你必须有一个空的构造函数才能在class agenda中声明数组contacto arreglo[40];

因此,请将以下内容添加到 class contacto 中的公共部分:

contacto(){
/*you can init members...*/  
}

class agenda中,如果你陈述了一个函数并使用它,你必须实现它。从行中使用的默认构造函数 agenda agen;

所以如果你声明它,你必须放{}来实现它。 如果你不声明,那么你得到了默认值,因为没有其他构造函数。