SoloCodigo

Programación General => C/C++ => Mensaje iniciado por: Hypocrisy en Martes 21 de Abril de 2009, 00:52

Título: ERROR INEXPLICABLE
Publicado por: Hypocrisy en Martes 21 de Abril de 2009, 00:52
Hola...ya estoy de nuevo aqui...Al compilar un programa me sale un constante error que no consigo quitar. Se que el programa esta bien pero igualmente sale el maldito error.
El error que sale es el siguiente: :hitcomp: :hitcomp:
 expected unqualified-id before "namespace"  
 expected `,' or `;' before "namespace"
 [Build Error]  [main.o] Error 1

El codigo es este:
Código: C++
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <vector>
  5. #include "PaintShop.h"
  6. #include "Paint.h"
  7. #include "Tool.h"
  8. #include "PaintShopException.h"
  9.  
  10. using namespace std; ---> AQUI ME MARCA EL ERROR  
  11.  
  12. void addPaint(PaintShop *ps, Paint* paint);
  13. void addTool(PaintShop *ps, Tool* tool);
  14. void paintInfo(PaintShop* ps, string id);
  15.  
  16. int main(int argc, char *argv[]) {
  17.  
  18.     // Creating a PaintShop object
  19.     // -------------------------
  20.     PaintShop *ps = new PaintShop();
  21.  
  22.     // Creating Paint objects and adding them to the paints list of object ps
  23.     // ----------------------------------------------------------------------
  24.     Paint *paintObj1 = new Paint("P1", "Plastic", "Red");
  25.     Paint *paintObj2 = new Paint("P2", "Acrylic", "Green");
  26.     Paint *paintObj3 = new Paint("P1", "Plastic", "Red"); // repeated object <----
  27.     ps->addPaint(paintObj1);
  28.     ps->addPaint(paintObj2);
  29.     ps->addPaint(paintObj3);
  30.  
  31.     // Creating Tool objects and adding them to the tools list of object ps
  32.     // --------------------------------------------------------------------
  33.     Tool *toolObj1 = new Tool("T1", "Paintbrush");
  34.     Tool *toolObj2 = new Tool("T2", "Paintroller");
  35.     Tool *toolObj3 = new Tool("T1", "Paintbrusch"); // repeated object <----
  36.     ps->addTool(toolObj1);
  37.     ps->addTool(toolObj2);
  38.     ps->addTool(toolObj3);
  39.  
  40.     // Listing Paint objects Information
  41.     // ---------------------------------
  42.     cout << "--------------" << endl;
  43.     cout << "List of paints" << endl;
  44.     cout << "--------------" << endl;
  45.     cout << ps->listPaints() << endl;
  46.  
  47.     // Listing Tool objects Information
  48.     // --------------------------------
  49.     cout << "-------------" << endl;
  50.     cout << "List of tools" << endl;
  51.     cout << "-------------" << endl;
  52.     cout << ps->listTools() << endl;
  53.  
  54.  
  55.     // Searching Paints by its id
  56.     // --------------------------
  57.     cout << "-- Information related to Paint with id = P1:" << endl;
  58.     paintInfo(ps,"P1");
  59.  
  60.     cout << "-- Information related to Paint with id = P3:" << endl;
  61.     paintInfo(ps,"P3");// This object does not exists <----
  62.  
  63.     // Comparing objects
  64.     // -----------------
  65.     cout << paintObj1->equals(paintObj2) << endl;
  66.     cout << paintObj1->equals(paintObj3) << endl;
  67.     cout << "End of the exercise" << endl;
  68. }
  69.  
  70. void addPaint(PaintShop *ps, Paint* paint)
  71. {
  72.     try
  73.     {
  74.         ps->addPaint(paint);
  75.     }
  76.     catch(PaintShopException e)
  77.     {
  78.         cout << e.str() << endl;
  79.     }
  80. }
  81.  
  82. void addTool(PaintShop *ps, Tool* tool)
  83. {
  84.     try
  85.     {
  86.         ps->addTool(tool);
  87.     }
  88.     catch(PaintShopException e)
  89.     {
  90.         cout << e.str() << endl;
  91.     }   
  92. }
  93. void paintInfo(PaintShop *ps, string id)
  94. {
  95.     try
  96.     {
  97.         cout << ps->paintInfo(id) << endl;
  98.     }
  99.     catch(PaintShopException e)
  100.     {
  101.         cout << e.str() << endl;
  102.     }   
  103. }
  104.  
  105.  

Me he mirado el codigo 20 millones de veces y nose porque sale . Me he mirado las otras clases y todas estan bien..que ocurre? es un problema del dev c++¿??
Título: Re: ERROR INEXPLICABLE
Publicado por: Eternal Idol en Martes 21 de Abril de 2009, 08:08
Seguro esta en la cabecera anterior al namespace: "PaintShopException.h".
Título: Re: ERROR INEXPLICABLE
Publicado por: Hypocrisy en Martes 21 de Abril de 2009, 11:24
Pero si esta bien O_o....que tengo que mirar dentro de las otras clases o algo? pk me lo he mirado tambien y lo veo correcto. --_--'''
Título: Re: ERROR INEXPLICABLE
Publicado por: Eternal Idol en Martes 21 de Abril de 2009, 11:29
El compilador esta esperando un punto y coma, tal vez no lo hayas puesto al final de una clase ... comproba esa cabecera de nuevo y con atencion.
Título: Re: ERROR INEXPLICABLE
Publicado por: Hypocrisy en Martes 21 de Abril de 2009, 11:45
tu has visto algo incohorente???? :wub:

EI: juntando mensajes.

 Ya he encontrado el error...era un } que sobraba en la clase paintshop. Compilo y me da Ok. Pero cuando ejecuto el programa me sale un mensaje: abnormal program termination :S. Sabes a que se debe????
Título: Re: ERROR INEXPLICABLE
Publicado por: Eternal Idol en Martes 21 de Abril de 2009, 13:18
Obviamente que no pude ver nada, todavia no tengo poderes mentales de ese tipo, simplemente use mi bola de cristal y adivine donde estaba el problema.

La excepcion se debe a codigo erroneo; depuralo.