473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
5 15275
Banfa
9,065 Expert Mod 8TB
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
gyre
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
gyre
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
9,065 Expert Mod 8TB
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
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

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

Similar topics

19
by: qazmlp | last post by:
class base { // other members public: virtual ~base() { } virtual void virtualMethod1()=0 ; virtual void virtualMethod2()=0 ; virtual void virtualMethod3()=0 ;
4
by: Tony Johansson | last post by:
Hello!! I'm reading a book about C++ and there is something that I don't understand so I ask you. The book says "The set of all public features of a class is called a public inteface, or...
3
by: marv | last post by:
If I have abstract base classes like these: //--------- class IBase { public: virtual void Action(void) = 0; };
3
by: enchantingdb | last post by:
I have an exam tomorrow that covers the perceived advantages and disadvantages of object oriented programming, in particular polymorphism, inheritance and encapsulation. I know the advantages but...
3
by: Andre Ranieri | last post by:
I downloaded VS 2005 web express beta 2 the other day for the purposes of learning more about it and seeing what is involved with converting my ASP.NET code base from 1.1 to 2.0. I've read a few...
2
by: Edd | last post by:
Hello all, Please consider: class Base { public: int pub; protected: int prot; private: int priv; };
0
by: erik.erikson | last post by:
I am getting a compiler error that I can't well explain or even understand the origin of (though I boiled it down close...). Below is a bare-bones example. What I am doing is defining the...
2
by: beseecher | last post by:
Hi, In my research in the javascript language I have encountered problems with implementing prototype inheritance while preserving private methods functioning properly. Here is an example: ...
4
by: Przemyslaw Koprowski | last post by:
Hi, I have the following problem. Consider two simple classes AA and BB, BB inherits from AA. AA contains a class A inside and a pure virtual method getA returning an object of class A. BB...
11
by: John | last post by:
Hi All, Although C# has Generics, it still does not support the generic programming paradigm. Multiple inheritance is required to support real generic programming. Here is a simple design pattern...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.