[C con Clase] Constructor en estructuras no funciona
Gonzalo Uribe
neogonxy en gmail.com
Sab Oct 6 20:30:35 CEST 2012
Buenas, tengo un problema cuando trato de inicializar una estructura, pero
me sale un error. Leí 5 veces la categoría de estructuras pero no encuentro
el error.
El error exactamente está en esta parte:
//Declaramos variables
>
> int opcion;
>
> char buscador[25];
>
> struct Datos{
>
> char nombre[25];
>
> char telefono[25];
>
> Datos();
>
> } personas[10];
>
>
>
> //Definición constructor
>
> Datos::Datos() {
>
> for(int i=0; i<25; i++){
>
> nombre[i] = '0';
>
> telefono[i] = 'a';
>
> }
>
> }
>
>
El código completo (por si se necesita) es este:
#include <cstdlib>
>
> #include <iostream>
>
>
>> using namespace std;
>
>
>> int main(int argc, char *argv[])
>
> {
>
> //Declaramos variables
>
> int opcion;
>
> char buscador[25];
>
> struct Datos{
>
> char nombre[25];
>
> char telefono[25];
>
> Datos();
>
> } personas[10];
>
>
>
> //Definición constructor
>
> Datos::Datos() {
>
> for(int i=0; i<25; i++){
>
> nombre[i] = '0';
>
> telefono[i] = 'a';
>
> }
>
> }
>
>
>
> //Inicializamos arrays
>
> for(int i=0; i<25; i++){
>
> buscador[i] = '0';
>
> }
>
>
>>
>
> //Pedimos los datos
>
> cout<<"Ingrese los datos de 10 personas con su numero de
>> telefono"<<endl;
>
> for (int i=0; i<10; i++){
>
> cout<<"Nombre "<<i+1<<":"<<endl;
>
> cin>>personas[i].nombre;
>
> cout<<"Telefono "<<i+1<<":"<<endl;
>
> cin>>personas[i].telefono;
>
> }
>
>
>
> //Comienza bucle principal
>
> cout<<"Gracias, ahora seleccione una opcion"<<endl;
>
> for(int bucle=0; bucle == 0;) {
>
> bucle = 0;
>
> cout<<endl<<endl;
>
> cout<<"1) Buscar por nombre"<<endl;
>
> cout<<"2) Buscar por telefono"<<endl;
>
> cout<<"3) Salir"<<endl;
>
> cin>>opcion;
>
> if(opcion == 3) bucle = 1;
>
> if(opcion == 1) cout<<"1"<<endl;
>
> if(opcion == 2) cout<<"2"<<endl;
>
> }
>
>
>
>
>
>
>
> system("PAUSE");
>
> return EXIT_SUCCESS;
>
>
>
> }
>
>
Uso el complicador Dev C++ 4.9.9.2.
Gracias de antemano :D
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.conclase.net/pipermail/cconclase_listas.conclase.net/attachments/20121006/7c15b7b7/attachment.html>
Más información sobre la lista de distribución Cconclase