LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-23-2006, 02:29 AM   #1
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Rep: Reputation: 30
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

Last edited by lucky6969b; 03-23-2006 at 02:43 AM.
 
Old 03-23-2006, 03:34 AM   #2
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
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?
 
Old 03-23-2006, 05:56 AM   #3
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
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>

Last edited by dmail; 03-23-2006 at 06:34 AM.
 
Old 03-23-2006, 07:54 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
printk --- ISO C90 forbids mixed declaration and code Igor007 Programming 3 09-08-2005 04:05 AM
Can not download JAVA PLUGIN for firefox says client forbids lcw321 Linux - Newbie 4 06-23-2005 03:24 AM
Proxy forbids port 1863 tunnelling koodoo Linux - Newbie 0 04-24-2005 01:11 PM
Does anyone Know how to open either .iso.rz or these .iso.xdelta,.iso.bz2,.iso.lzma?? maximalred Debian 5 06-09-2004 06:15 AM
ISO C++ forbids comparison between pointer and integer? pimaster Programming 1 11-06-2003 01:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration