Ver Mensaje Individual
  #6 (permalink)  
Antiguo 17/03/2016, 06:53
tonyasura
 
Fecha de Ingreso: marzo-2016
Mensajes: 8
Antigüedad: 8 años, 1 mes
Puntos: 0
Respuesta: Problema con includes y clases una dentro de la otra

Código C++:
Ver original
  1. #ifndef CLASE1_H
  2. #define CLASE1_H
  3.  
  4. class Clase2;
  5.  
  6. class   Clase1 {
  7. public:
  8. Clase1(){};
  9.  
  10. void setClase(Clase2 * c ){c2 = c;}
  11.  
  12. void unaFuncion(){
  13. //idea 1
  14.     Clase2 c=*c2;//  ERROR
  15.      c.unaFuncion();
  16. //idea 2
  17. c2.unaFuncion(); //Description  Resource    Path    Location    Type    request for member 'unaFuncion' in '((Clase1*)this)->Clase1::c2', which is of pointer type 'Clase2*' (maybe you meant to use '->' ?)    Clase1.h    /test_incluse   line 14 C/C++ Problem
  18. };
  19.  
  20. Clase2 * c2;
  21.     };
  22.  
  23. #endif
  24.  
  25.  
  26. #ifndef CLASE2_H
  27. #define CLASE2_H
  28.  
  29. class   Clase2 {
  30. public:
  31. Clase2(){};
  32.  
  33. void setClase(Clase1 * c ){c1 = c;}
  34.  
  35. void unaFuncion(){
  36.     Clase1 c=*c1;
  37.     c.unaFuncion();
  38. };
  39.  
  40. Clase1 * c1;
  41.  
  42.     };
  43.  
  44. #endif

bueno... he avanzado un poquito gracias a vosotros.

Ahora me quedaría solventar esa línea.


Efectivamente, las clases estarían cada una en su propio fichero, este código es solo un ejemplo.

este es el resto del código:

Código C++:
Ver original
  1. //The setup function is called once at startup of the sketch
  2.  
  3. #include "Clase1.h"
  4.  
  5. Clase1 c1;
  6. Clase2 c2;
  7. void setup()
  8. {
  9.  c1 = Clase1();
  10.  c2 = Clase2();
  11.  
  12.  c1.setClase(&c2);
  13.  c2.setClase(&c1);
  14.  
  15.  
  16. }
  17.  
  18. void loop()
  19. {
  20.  
  21. }

Gracias por todo