LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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-14-2006, 01:14 AM   #1
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Rep: Reputation: 30
Does not name a type error


src/rs232.h:17: error: expected class-name before ‘{’ token
src/rs232.h:31: error: ‘NOX’ does not name a type
src/rs232.h:32: error: ‘HC’ does not name a type
src/rs232.h:33: error: ‘CO’ does not name a type
src/rs232.h:34: error: ‘CO2’ does not name a type
make: *** [rmves.o] Error 1

===================== CODE
#ifndef __RMVES__
#define __RMVES__
/******************************
Version 2.0
Purpose: define the most basic
type of objects
******************************/
#include <list>
#include "rs232.h"

#define TRUE 1
#define FALSE 0

using namespace std;

class SubjectEx;
//=======================================
// Class: Observer
// Purpose: Updating Subject
// after receiving signals
// from the sensors
//=======================================
class Observer
{
public:
virtual ~Observer() { }
virtual void Update (SubjectEx *theChangedSubject) = 0;
protected:
Observer() { }
};

//=======================================
// Class: Subject
// Purpose: Monitoring the RS232
//=======================================
class SubjectEx {
public:
virtual ~SubjectEx() { }

virtual void Attach (Observer *) = 0;
virtual void Detach (Observer *) = 0;
virtual void Notify (Observer *) = 0;
protected:
SubjectEx() { }
private:
list<Observer *>*m_Observer;
};

//=======================================
// Class: NOX
// Purpose: class that represent the NOX
// gas reading
//=======================================
class NOX : public Observer {
public:
NOX() { }
~NOX() { }
virtual void Update (SubjectEx *);

// Get/Set functions
void SetNOX (double _NOX) { m_fNOXReading = _NOX; }
double GetNOX() { return m_fNOXReading; }

private:
double m_fNOXReading;
RS232_Controller *m_oSubject;
};

//=======================================
// Class: HC
// Purpose: class that represent HC
// gas reading
//=======================================
class HC : public Observer {
public:
HC() { }
~HC() { }
virtual void Update (SubjectEx *);

// Get/Set
void SetHC( double _HC ) { m_fHCReading = _HC; }
double GetHC() { return m_fHCReading; }
private:
double m_fHCReading;
RS232_Controller *m_oSubject;
};

//=======================================
// Class: CO2
// Purpose: class that represent CO2
// gas reading
//=======================================
class CO2 : public Observer {
public:
CO2() { }
~CO2() { }
virtual void Update (SubjectEx *);

// Get/Set
void SetCO2 (double _CO2) { m_fCO2Reading = _CO2; }
double GetCO2() { return m_fCO2Reading; }
private:
double m_fCO2Reading;
RS232_Controller *m_oSubject;
};

//=====================================
// Class: CO
// Purpose: class represents the CO
// gas reading
//=====================================
class CO : public Observer
{
public:
CO() { }
~CO() { }
virtual void Update (SubjectEx *);

// Get/Set
void SetCO(double _CO) { m_fCOReading = _CO; }
double GetCO() { return m_fCOReading; }
private:
double m_fCOReading;
RS232_Controller *m_oSubject;
};
#endif


================ End of rmves.h

#ifndef __RS232__
#define __RS232__
/**************************
Version 2.0
Purpose: Defines RS232
Controller
***************************/
#include "rmves.h"

#define MAX_THREADS 10

//=========================================
// Class: RS232_Controller
// Purpose: Controlling the RS232 interface
//=========================================
class RS232_Controller : public SubjectEx
{
public:
bool CreateThread(void);
// Join the thread pool
void Join (pthread_t pthread);

// Thunk that wraps C Thread Objects
void *PortMonitorThread(void*);

pthread_t getThread (int index) { return m_Threads[index]; }
public:
RS232_Controller() { }
~RS232_Controller() { }
private:
NOX m_oNOX;
HC m_oHC;
CO m_oCO;
CO2 m_oCO2;
pthread_t m_Threads[MAX_THREADS];
};
#endif

=============End of file rs232.h

Any ideas?
Thanks
Jack
 
Old 03-14-2006, 07:16 AM   #2
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
This problem is caused when you are recursively including header files.... There is no problem in the code... Just try to include header files in some other sequence... Like include both headers in main file not in each other or something like that....
Also see the link given below... Can be helpful for you

http://gcc.gnu.org/ml/gcc-help/2005-06/msg00097.html
 
Old 03-14-2006, 07:54 PM   #3
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
Hi,
I put the 2 lines of code into rmves.cpp
#include <iostream>
#include "rmves.h"
#include "rs232.h"


RS232_Controller *rs232;

int main (int argc, char *argv[])
{
bool res;
pthread_t tid;

rs232 = new RS232_Controller();
res = rs232->CreateThread();
rs232->Join(rs232->getThread(0));
return 0;
}

==============================================================
[root@localhost Ver2_0]# make
if g++ -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"rmves\" -DVERSION=\"2.0\" -I. -I. -I -I. -I/opt/arcom/arcom-linux/include -I/usr/local/include -I/opt/arcom/arcom-linux/include/glib2.0 -g -O2 -MT rmves.o -MD -MP -MF ".deps/rmves.Tpo" -c -o rmves.o `test -f 'src/rmves.cpp' || echo './'`src/rmves.cpp; \
then mv -f ".deps/rmves.Tpo" ".deps/rmves.Po"; else rm -f ".deps/rmves.Tpo"; exit 1; fi
src/rmves.cpp:17:2: warning: no newline at end of file
src/rmves.h:66: error: ISO C++ forbids declaration of ‘RS232_Controller’ with no type
src/rmves.h:66: error: expected ‘;’ before ‘*’ token
src/rmves.h:85: error: ISO C++ forbids declaration of ‘RS232_Controller’ with no type
src/rmves.h:85: error: expected ‘;’ before ‘*’ token
src/rmves.h:104: error: ISO C++ forbids declaration of ‘RS232_Controller’ with no type
src/rmves.h:104: error: expected ‘;’ before ‘*’ token
src/rmves.h:124: error: ISO C++ forbids declaration of ‘RS232_Controller’ with no type
src/rmves.h:124: error: expected ‘;’ before ‘*’ token
src/rmves.cpp: In function ‘int main(int, char**)’:
src/rmves.cpp:13: error: cannot allocate an object of abstract type ‘RS232_Controller’
src/rs232.h:17: note: because the following virtual functions are pure within ‘RS232_Controller’:
src/rmves.h:40: note: virtual void SubjectEx::Attach(Observer*)
src/rmves.h:41: note: virtual void SubjectEx:etach(Observer*)
src/rmves.h:42: note: virtual void SubjectEx::Notify(Observer*)
make: *** [rmves.o] Error 1

Thanks
Jack
 
Old 03-15-2006, 08:22 AM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Code:
src/rmves.cpp:13: error: cannot allocate an object of abstract type ‘RS232_Controller’
src/rs232.h:17: note: because the following virtual functions are pure within ‘RS232_Controller’:
src/rmves.h:40: note: virtual void SubjectEx::Attach(Observer*)
src/rmves.h:41: note: virtual void SubjectEx:etach(Observer*)
src/rmves.h:42: note: virtual void SubjectEx::Notify(Observer*)
you are attempting to create a rs232 here
Code:
rs232 = new RS232_Controller();
but you cannot do that because r232 inherits pure virtual functions which you do not define.. so it is abstract..

so either define Attach, Detach, Notify or dont create a rs232

and also please try to figure out the code tags.. i know they are tough to use, but give it a shot..
 
  


Reply



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
mime type error with k3b linuxmandrake Debian 1 09-30-2005 08:49 AM
Used but not defined as type error ChemicalBurn Programming 2 05-24-2005 08:04 AM
When I type Wine in BASH, I get an error. cheeseincarnate Linux - Software 1 06-16-2004 11:51 PM
Wierd POD type error teval Programming 1 08-18-2003 06:32 PM
error when type ./configure eduac Linux - Software 3 07-10-2003 01:35 PM

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

All times are GMT -5. The time now is 10:43 AM.

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
Open Source Consulting | Domain Registration