By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 2,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

inheritance problem: error: expected class-name before '{' token

P: 3
Hi!
I've got a little problem I've been dealing with for several days :((
Code is written in Qt.
I'll try to explain it:

I created an abstract class "VcaNode" with 4 virtual methods and 3 other members...it is in special header:

Expand|Select|Wrap|Line Numbers
  1. //ABSTRACT CLASS MEMBER:
  2. #ifndef _VCA_NODE
  3. #define _VCA_NODE
  4.  
  5. #include <vca_net.h>
  6. #include <canmsg.h>
  7.  
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. #include <QObject>
  12.  
  13. class VcaNet;
  14.  
  15. class VcaNode : public QObject
  16. {
  17.   Q_OBJECT
  18.  
  19.   public:
  20.     VcaNet *cannet;
  21.  
  22.     VcaNode(VcaNet *parent){
  23.       this->cannet = parent;
  24.     };
  25.     virtual ~VcaNode() {cout <<"Node Has Been destroyed/disconnected"<<endl;};
  26.  
  27.     void emitSentSignal(int event_code, const canmsg_t *canmsg){
  28.       emit sentMsg(event_code, canmsg);
  29.     }
  30.  
  31.    virtual void connectNode() = 0;
  32.    virtual int  vcaSendMsgSeq(canmsg_t *messages, int count) = 0;
  33.    virtual int  vcaRecMsgSeq(canmsg_t *messages, int count) = 0;
  34.  
  35.    signals:
  36.      void sentMsg(int event_code, const canmsg_t *canmsg);
  37.  
  38.    public slots:
  39.      virtual void nodeReady() = 0;
  40.  
  41. };
  42. #endif

Then I want to inherit it and override virtual methods ...So I created another class "VcaFdNode" that looks like this:
Expand|Select|Wrap|Line Numbers
  1. //INHERITED CLASS 
  2. #ifndef _CAN_VCA_H
  3. #define _CAN_VCA_H
  4.  
  5. #include <vca_net.h>
  6. #include <vca_node.h>
  7. #include <vca_net.h>
  8.  
  9. #include <QObject>
  10. #include <QSocketNotifier>
  11.  
  12. #include <stdarg.h>
  13. #ifndef __RTL__
  14. #include <sys/time.h>
  15. #else /*__RTL__*/
  16. #include <time.h>
  17. #endif /*__RTL__*/
  18. #include <can.h>
  19.  
  20. class VcaNet;
  21. //class VcaNode;
  22.  
  23. class VcaFdNode : public VcaNode
  24. {
  25.   private:
  26.     int vcah;
  27.  
  28.     int  vcaWait(int wait_msec, int what);
  29.     long vcaH2log();
  30.  
  31.   public:
  32.     bool vca_ok;
  33.     QSocketNotifier *sn;
  34.  
  35.     VcaFdNode(VcaNet *_cannet, const char *dev_name/*, const char *options, int flags*/);
  36.     ~VcaFdNode();
  37.  
  38.     void connectNode();//OK
  39.     int  vcaSendMsgSeq(canmsg_t *messages, int count);//OK
  40.     int  vcaRecMsgSeq(canmsg_t *messages, int count);//OK
  41.  
  42.     int  getVcaHandle();
  43.     void setVcaHandle(int handle);
  44.     int  vcaH2fd();
  45.  
  46.   public slots:
  47.     void nodeReady();//OK
  48.  
  49. };
  50. #endif
But when I try to compile source code using these header I got this error:
./vca_fdnode.h:23: error: expected class-name before '{' token
vca_fdnode.cpp: In constructor 'VcaFdNode::VcaFdNode(VcaNet*, const char*)':
vca_fdnode.cpp:63: error: type 'VcaNode' is not a direct base of 'VcaFdNode'

and so on :(

ANYONE help ? :)

THANKS A LOT IN ADVANCE...
Sep 21 '07 #1
Share this Question
Share on Google+
5 Replies


Banfa
Expert Mod 5K+
P: 8,916
Expand|Select|Wrap|Line Numbers
  1. //ABSTRACT CLASS MEMBER:
  2. #ifndef _VCA_NODE
  3. #define _VCA_NODE
  4.  
  5. #include <vca_net.h>
  6. #include <canmsg.h>
  7.  
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. #include <QObject>
  12.  
  13. class VcaNet;
  14.  
  15. class VcaNode : public QObject
  16. {
  17. <snipped>
  18. };
  19. #endif
The line "class VcaNet;" should not be required here as I assume that VcaNet is declared in vca_net.h. That it exists suggests to me that possibly it was put in to solve a problem and this intern suggests a interoperability problem with vca_net.h and vca_node.h.


Expand|Select|Wrap|Line Numbers
  1. //INHERITED CLASS 
  2. #ifndef _CAN_VCA_H
  3. #define _CAN_VCA_H
  4.  
  5. #include <vca_net.h>
  6. #include <vca_node.h>
  7. #include <vca_net.h>
  8.  
  9. #include <QObject>
  10. #include <QSocketNotifier>
  11.  
  12. #include <stdarg.h>
  13. #ifndef __RTL__
  14. #include <sys/time.h>
  15. #else /*__RTL__*/
  16. #include <time.h>
  17. #endif /*__RTL__*/
  18. #include <can.h>
  19.  
  20. class VcaNet;
  21. //class VcaNode;
  22.  
  23. class VcaFdNode : public VcaNode
  24. {
  25. <snipped>
  26. };
  27. #endif
And here is you actual problem, VcaNode is not recognised as a class name for some reason. Again the unrequired declaration of VcaNet. Noticing that vca_net.h is included before vca_node.h and taking into account the previous stated problem I would be checking vca_net.h to ensure that it wasn't accidentally using the same double inclusion protection symbol (_VCA_NODE) as vca_node.h.
Sep 21 '07 #2

P: 3
Expand|Select|Wrap|Line Numbers
  1. //ABSTRACT CLASS MEMBER:
  2. #ifndef _VCA_NODE
  3. #define _VCA_NODE
  4.  
  5. #include <vca_net.h>
  6. #include <canmsg.h>
  7.  
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. #include <QObject>
  12.  
  13. class VcaNet;
  14.  
  15. class VcaNode : public QObject
  16. {
  17. <snipped>
  18. };
  19. #endif
The line "class VcaNet;" should not be required here as I assume that VcaNet is declared in vca_net.h. That it exists suggests to me that possibly it was put in to solve a problem and this intern suggests a interoperability problem with vca_net.h and vca_node.h.


Expand|Select|Wrap|Line Numbers
  1. //INHERITED CLASS 
  2. #ifndef _CAN_VCA_H
  3. #define _CAN_VCA_H
  4.  
  5. #include <vca_net.h>
  6. #include <vca_node.h>
  7. #include <vca_net.h>
  8.  
  9. #include <QObject>
  10. #include <QSocketNotifier>
  11.  
  12. #include <stdarg.h>
  13. #ifndef __RTL__
  14. #include <sys/time.h>
  15. #else /*__RTL__*/
  16. #include <time.h>
  17. #endif /*__RTL__*/
  18. #include <can.h>
  19.  
  20. class VcaNet;
  21. //class VcaNode;
  22.  
  23. class VcaFdNode : public VcaNode
  24. {
  25. <snipped>
  26. };
  27. #endif
And here is you actual problem, VcaNode is not recognised as a class name for some reason. Again the unrequired declaration of VcaNet. Noticing that vca_net.h is included before vca_node.h and taking into account the previous stated problem I would be checking vca_net.h to ensure that it wasn't accidentally using the same double inclusion protection symbol (_VCA_NODE) as vca_node.h.
I changed it according to your advice...removed previous declaration of VcaNet class...didn't help...
_VCA_NODE symbol is used only in vca_node.h header...still dunno :(
Sep 22 '07 #3

P: 3
I changed it according to your advice...removed previous declaration of VcaNet class...didn't help...
_VCA_NODE symbol is used only in vca_node.h header...still dunno :(
Btw...when I replaced that VcaNet declaration...then compiler threw even more errors - vca_node.h did not recognize VcaNet class...
When I put all classes in one header file everything is compiled OK...
hm getting frustrated and mad more and more ;(
Sep 22 '07 #4

Banfa
Expert Mod 5K+
P: 8,916
Btw...when I replaced that VcaNet declaration...then compiler threw even more errors - vca_node.h did not recognize VcaNet class...
When I put all classes in one header file everything is compiled OK...
hm getting frustrated and mad more and more ;(
I think seeing vca_net.h would help.
Sep 23 '07 #5

P: 1
Try this (sorry for my english):

//INHERITED CLASS

#include <vca_net.h>
#include <vca_node.h>
#include <vca_net.h>
#include <QObject>
#include <QSocketNotifier>
#include <stdarg.h>
#ifndef __RTL__
#include <sys/time.h>
#else /*__RTL__*/
#include <time.h>
#endif /*__RTL__*/
#include <can.h>

class VcaNet;
//class VcaNode;

// put the headerprotection here, otherwise you will get an error!
#ifndef _CAN_VCA_H
#define _CAN_VCA_H

class VcaFdNode : public VcaNode
{
<snipped>
};
#endif
Sep 27 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.