views:

72

answers:

3

Hello, everyone.

I am having some trouble on a project I'm working on.

Here's the header file for the calor class:

#ifndef _CALOR_
#define _CALOR_

#include "gradiente.h"

using namespace std;

class Calor : public Gradiente
{
public:
    Calor();
    Calor(int a);
    ~Calor();

    int getTemp();
    int getMinTemp();
    void setTemp(int a);
    void setMinTemp(int a);

    void mostraSensor();
};
#endif

When I try to compile it:

calor.h|6|error: expected unqualified-id before ‘using’|

Why does this happen? I've been searching online and learned this error occurs mostly due to corrupted included files. Makes no sense to me, though. This class inherits from gradiente:

#ifndef _GRADIENTE_
#define _GRADIENTE_

#include "sensor.h"

using namespace std;

class Gradiente : public Sensor
{
protected:
    int vActual, vMin;
public:
    Gradiente();
    ~Gradiente();
}
#endif

Which in turn inherits from sensor

#ifndef _SENSOR_
#define _SENSOR_

#include <iostream>
#include <fstream>
#include <string>

#include "definicoes.h"

using namespace std;

class Sensor
{
protected:
    int tipo;
    int IDsensor;
    bool estadoAlerta;
    bool estadoActivo;
    static int numSensores;
public:
    Sensor(/*PARAMETROS*/);
    Sensor(ifstream &);
    ~Sensor();

    int getIDsensor();
    bool getEstadoAlerta();
    bool getEstadoActivo();

    void setEstadoAlerta(int a);
    void setEstadoActivo(int a);

    virtual void guardaSensor(ofstream &);
    virtual void mostraSensor();
    // FUNÇÃO COMUM
    /* virtual int funcaoComum() = 0;
    virtual int funcaoComum(){return 0;};*/
};
#endif

For completeness' sake, here's definicoes.h

#ifndef _DEFINICOES_
#define _DEFINICOES_

const unsigned int SENSOR_MOVIMENTO = 0;
const unsigned int SENSOR_SOM = 1;
const unsigned int SENSOR_PRESSAO = 2;
const unsigned int SENSOR_CALOR = 3;
const unsigned int SENSOR_CONTACTO = 4;

const unsigned int MIN_MOVIMENTO = 10;
const unsigned int MIN_SOM = 10;
const unsigned int MIN_PRESSAO = 10;
const unsigned int MIN_CALOR = 35;
#endif

Any help'd be much appreciated.

Thank you for your time.

+7  A: 

In gradiente.h you forgot the semicolon at the end of your class declaration.

You need this:

class Gradiente : public Sensor
{
    protected:
        int vActual, vMin;
    public:
        Gradiente();
        ~Gradiente();
};  

See the added semicolon?

George
["Ah, the missing semicolon... The only reason girls would talk to me back in the uni days."](http://www.reddit.com/r/programming/comments/b8ws6/) `:)`
sbi
+2  A: 

You forgot to leave the last semi colon on the closing brackets, };, on the gradiente class.

wheaties
+6  A: 

There is a semicolon missing at the end of this class:

class Gradiente : public Sensor
{
protected:
    int vActual, vMin;
public:
    Gradiente();
    ~Gradiente();
}

Also, the names of your include guards are illegal. Names that begin with an underscore and an uppercase letter are reserved for the C++ implementation (as are names containing a double underscore) - you are not allowed to create such names in your own code. And you should never use:

using namespace std;

in a header file. And lastly, the destructor in your Sensor base class should almost certainly be made virtual.

anon
Thank you for your added corrections!
Francisco P.
Just to clarify, the reason you should never use "using namespace std" (or that with any other namespace, for that matter) is because users of your class won't be expecting their global namepace to get polluted with all this stuff from namespace std when they didn't ask for it. Usually you want to limit how much stuff you add to the global namespace in your headers to the minimum required to get the job done, otherwise you risk introducing name conflicts and other fun stuff.
George