I have a C++ program and when I try to compile it it开发者_开发百科 gives an error:
calor.h|6|error: expected unqualified-id before ‘using’|
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
Why does this happen?
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
What am I doing wrong?
There is a semicolon missing at the end of this class:
class Gradiente : public Sensor
{
protected:
int vActual, vMin;
public:
Gradiente();
~Gradiente();
} // <-- semicolon needed after the right curly brace.
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.
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?
You forgot to leave the last semi colon on the closing brackets, };
, on the gradiente class.
精彩评论