LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   ISO C++ forbids declaration of... (https://www.linuxquestions.org/questions/programming-9/iso-c-forbids-declaration-of-427566/)

lucky6969b 03-23-2006 02:29 AM

ISO C++ forbids declaration of...
 
[root@localhost test-analysis]# g++ -o test1 test1.cpp Math2.cpp LinearRegression.cpp
test1.h:28: error: ISO C++ forbids declaration of ‘MathEx’ with no type
test1.h:28: error: expected ‘;’ before ‘*’ tok

CODE====================================================
Math2.h

#ifndef __MATHEX__
#define __MATHEX__

#include "test1.h"

typedef double Real;
typedef struct { Real r; Real i; } Complex;
typedef Real* Real_Vector;


#define BYTE short

class MathEx {
public:
MathEx() { }
~MathEx() { }

void least_sq(void);
void gas_equation(void);
void Linear_Regression(const float *x, const float *y, int n, float *m, float *b, float *rsq );

};
#endif

===================================================
test1.h

#ifndef __PLUMEANALYSIS__
#define __PLUMEANALYSIS__

#include "Math2.h"

typedef float PlumeData; // Placeholder

class PlumeAnalysis
{
public:
PlumeAnalysis() : m_pMath() { }
~PlumeAnalysis() { delete m_pMath; }

void Calibration(void);
void Calculate (PlumeData *p);
//void LinearRegression(void);
void Ask_USB_Device(void);
void StoreDatabase(void);
void GetData(void);
void GetRef(void);
void GetDark(void);
void GetValues(void);
void Analyse(void);
void StoreDataBase(void);
private:
bool m_bInterrupt;

MathEx *m_pMath; <<<<<<<<<<<<<<<<<<<<<< Error

private:
double m_CO_CO2_Ratio;
double m_HC_CO2_Ratio;
double m_NOX_CO2_Ratio;

float m_Result_CO;
float m_Result_CO2;
float m_Result_HC;
float m_Result_NOX;

};
#endif

=======================================================
test1.cpp

#include "test1.h"

int main (int argc, char *argv[])
{
PlumeAnalysis *analysis;

analysis = new PlumeAnalysis();
analysis->Analyse();
return 0;
}

========================================================
LinearRegression.h

#include "test1.h"



void PlumeAnalysis::Analyse(void)
{
PlumeData *p;
GetData();
Calculate(p);
StoreDatabase();
}



void PlumeAnalysis::Calculate(PlumeData *pPlume)
{
float fDenominator;

// Considering points that would abruptly out of scale, there might be problems
// with those readings. So they might be dropped off and dispose of.

// Numerical methods that are used to plot a straight line over many reading points
m_pMath->LinearRegression (pPlume->CO2Array, pPlume->COArray, total, &m_CO2SlopeCO, &m_CO2InterceptCO, &m_CO2SlopeCOmse);

// HC Readings should usually lower than CO and CO2
m_pMath->LinearRegression (pPlume->CO2Array, pPlume->HCArray, total, &m_CO2SlopeCO,
&m_CO2InterceptHC, &m_HCSlipeHCmse);

m_pMath->LinearRegression (pPlume->CO2Array, pPlume->NOXArray, total, &m_CO2SlopeNOX,
&m_CO2InterceptNOX, &m_CO2SlopeNOXmse);




m_CO_CO2_Ratio = m_CO2SlopeCO;
m_HC_CO2_Ratio = m_CO2SlopeHC;
m_NOX_CO2_Ratio = m_CO2SlopeNOX;

// General formula that can be found in patents
fDenominator = 2.79 + 2.0 * m_CO_CO2_Ratio - 0.37 * m_HC_CO2_Ratio;

// I guess the following results don't fit in one scale, so
// they were multiplied by a large integer in Judge 31s
m_Result_CO = (42.0 * m_CO_CO2_Ratio) / dDenominator;
m_Result_CO2 = 42.0 / dDenominator;
m_Result_HC = (42.0 * m_HC_CO2_Ratio) / dDenominator;
m_Result_NOX = (42.0 * m_NOX_CO2_Ratio) / dDenominator;

}


void PlumeAnalysis::GetData(void)
{
Calibration();
for (;;)
{
if (m_bInterrupt) {
Ask_USB_Device();
GetRef();
GetDark();
for (;;) {
GetValues();
}
}
}
}

void PlumeAnalysis::Ask_USB_Device(void)
{
}

void PlumeAnalysis::GetRef(void)
{
}

void PlumeAnalysis::GetDark(void)
{
}

void PlumeAnalysis::GetValues(void)
{
}


void PlumeAnalysis::StoreDatabase(void)
{
}

void PlumeAnalysis::Calibration(void)
{
}

Thanks
Jack

lucky6969b 03-23-2006 03:34 AM

There should be no namespace problem. I changed the name of the class to different ones, but still got the same errors... So I wonder what causes it might be?

dmail 03-23-2006 05:56 AM

Is there any need for the header Math2.h to include "test1.h"? if not remove it and it should compile.
Code:

#define BYTE short
I can not see where you use a "BYTE" but your size and sign is wrong here, this is more like a nibble. try unsigned char.

Will you ever use code tags?


this will give you a seg fault.
Code:

void PlumeAnalysis::Analyse(void)
{
PlumeData *p;
GetData();
Calculate(p);
StoreDatabase();
}



void PlumeAnalysis::Calculate(PlumeData *pPlume)
{
float fDenominator;

m_pMath->LinearRegression (pPlume->CO2Array,.......


Code:

class PlumeAnalysis
{
public:
PlumeAnalysis() : m_pMath() { }//calling a function on an unintailised pointer?
~PlumeAnalysis() { delete m_pMath; }//calling delete on a pointer which has not been created with new???
.......
MathEx *m_pMath; <<<<<<<<<<<<<<<<<<<<<< Error


<edit>
Im really unsure what you are trying to do in the func
void PlumeAnalysis::Calculate(PlumeData *pPlume).
it takes as a param a PlumeData* which is a float*
Code:

typedef float PlumeData; // Placeholder
and then you derefence it and access???? hmmm I don't know what
Code:

....pPlume->CO2Array, pPlume->COArray,....
</edit>

graemef 03-23-2006 07:54 AM

well dmail has (as always) been very thorough. Just to add the reason you are getting the compiler error that you mentioned is because of the #includes that you have.

I'll try and explain to you what the compiler is doing.

It takes the Math2.h file and asks itself "what do we have here?" You're the programmer and smugly suggest that what we have here is the class MathEx. But the compiler disagrees, what we have here is a #include to the file test1.h, so we will, for the moment, stop looking at Math2.h and look at test1.h - remember at this point the compiler has not looked at the class MathEx. So it now looks at the file test1.h and asks itself "what do we have here?" It scours the code and says "Oh what's this a variable of type MathEx - but MathEx isn't a type I know of, I'm going to bail out her." Being the progammer you feel a little indignant that the compiler has followed your instruction exactly to the letter, if only it had a little more patience it would have found all about the class MathEx.

Briefly, that is how the C compiler works. Other languages work differently... In a situation where that is absolutely necessary you need to have forward declarations such as

Code:

class MathEx; // forward declaration
#include "test1.h" // A #include that will have a reference to the forward declaration

class MathEx // here we are the real thing
{
}

A forward declaration is a promise to the compiler that you'll learn about it all in good time.

I hope that helps. Just one request, please use the code tags, it's the little button with the #,

graeme.


All times are GMT -5. The time now is 12:04 PM.