elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Mensajes
Páginas: 1 2 [3]
21  Programación / Programación C/C++ / Problema llamando el método de una clase :/ en: 27 Noviembre 2016, 02:18 am
Hola en este pedazo de mi codigo:
Código
  1.  
  2. JugadorSolo a;
  3.  
  4.      for(int a =0;a <= 5; a++){
  5. for(int b = 0; b<=6; b++)
  6.                tablero[a][b] = ' ';
  7. }
  8.  
tengo que usar el arreglo "char tablero[6][7]" que forma parte de la clase JugadorSolo. Entonces cree un get en esta clase para poder reasignarlo a otra variable en el main y usarlo, pero al hacerlo me da un error, hago algo como esto:

Código
  1. JugadorSolo.h:
  2.  
  3. char JugadorSolo::getTablero()
  4. {
  5.    return tablero[6][7];
  6. }
  7.  
  8. int main:
  9.  
  10.    JugadorSolo a;
  11.  
  12.        for(int a =0;a <= 5; a++){
  13. for(int b = 0; b<=6; b++)
  14.           a.getTablero();
  15.  
  16. }
  17.  
Me da el error:
"Request for member "getTablero" in 'a', which is of non-class type 'int'

Despues intente haciendo todo el ciclo una funcion de la clase para poder utilizarlo entonces lo ponia algo asi:
    JugadorSolo a;
    a.ciclo();

Y aqui me da el error 'a' was not declared in this scope.

Despues intente poner esa variable en global y me da este error:

'tablero' was not declared in this scope


No se que hago mal o por qué de ninguna manera funciona, agradeceria mucho si alguien sabe.

Muchas gracias.



Mod: Los códigos deben ir en etiquetas GeSHi, no hacer doble post
22  Programación / Programación C/C++ / Duda [Sobrecarga de operadores] en: 22 Noviembre 2016, 21:03 pm
BUENOS DÍAS,DEBO ACLARAR QUE YA HABIA COMPILADO MI PROGRAMA SIN ERRORES EN UN MISMO ARCHIVO, PERO A LA HORA DE SEPARLO POR CLASES ME DA UN ERROR.

LA CLASE QUE ME DA ERROR ESTA COMPUESTA ASÍ:

#ifndef PREFERENCIA_H
#define PREFERENCIA_H
#include <iostream>
#include <string.h>
#include <fstream>
#include <stdlib.h>
#include "Cancion.h"
#include <ctype.h>

using namespace std;

class Preferencia
{
    public:
        float calidad, gusto;

        Preferencia(const float a,const float b)
        {
            calidad= a;
            gusto= b;
        }
};
Preferencia& operator +(const Preferencia &p1,const Preferencia &p2)
{
  return *(new Preferencia(p1.calidad + p2.calidad, p1.gusto + p2.gusto) );
}

#endif // PREFERENCIA_H

LA MANERA EN LA QUE LA USO EN EL MAIN:

    Preferencia A(50, 75 );
    Preferencia B(150, 175 );
    Preferencia C = A + B;

    cout << "A = " << A.calidad << ',' << A.gusto << "\n";
    cout << "B = " << B.calidad << ',' << B.gusto << "\n";
    cout << "C = " << C.calidad << ',' << C.gusto << "\n";
    cout<<endl;


NO TENIA NINGUN ERORR ANTES DE PONER ESA CLASE POR SEPARADA.

Esto es lo que me dice:

warning:suggest parentheses around assigment used as truth value (-Wparentheses)
In function 'ZN11PreferenciaCIEff':
multiple definition of 'operator+(Preferencia const&, Preferencia const&)' [line 24]
first defined here[line 24]
error:Id returned 1 exist status


Páginas: 1 2 [3]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines