Id 返回 1 个退出状态
Id returned 1 exit status
当我尝试编译它时弹出此错误(对不起,它是西班牙语)
#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;
所以如果你声明它,你必须放{}
来实现它。 如果你不声明,那么你得到了默认值,因为没有其他构造函数。
相关文章:
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 为什么系统函数总是在C++中返回已转移的退出状态?
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 试图在崇高中奔跑. 错误 已发生: 收集2.exe: 错误: ld 返回 1 退出状态
- collect2:错误:ld 返回 1 个退出状态未定义的引用
- C++ collect2:错误:ld 返回 1 退出状态
- 找不到 -llibmysqld Collect2.exe:错误:ld 返回 1 退出状态
- 每次我要使用外部资源时,我都会得到:collect2。exe:错误 ld 返回 1 退出状态
- 当出现错误ld return 1退出状态时,如何编译程序
- 无法访问 Arduino 结构字段。错误"退出状态 1。xxxx 不命名类型"
- "Extern"对象问题:错误:Id 返回 1 个退出状态
- c++ (C::B) 错误:ld 返回 1 个退出状态
- 在 c++ 中捕获 shell 脚本退出状态
- 对"displayForStudent(int, int const*, double const*, int)"的未定义引用 collect2.exe:错误:ld 返回 1 个退出状态
- 使用类[错误] LD返回1退出状态
- 如何解决退出状态 1 错误
- 错误 (Id) 返回 1 个退出状态
- 退出状态 1 令牌之前的预期主表达式'.'
- 错误:LD返回1个退出状态-CodeBlocks