473,569 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
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::Vca FdNode(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 15308
Banfa
9,065 Recognized Expert Moderator Expert
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 interoperabilit y 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 New Member
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 interoperabilit y 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...remove d 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 New Member
I changed it according to your advice...remove d 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...t hen 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 Recognized Expert Moderator Expert
Btw...when I replaced that VcaNet declaration...t hen 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
Turboente
1 New Member
Try this (sorry for my english):

//INHERITED CLASS

#include <vca_net.h>
#include <vca_node.h>
#include <vca_net.h>
#include <QObject>
#include <QSocketNotifie r>
#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 headerprotectio n 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
2322
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
366
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 simply interface. When the inheritance hierarchy is properly designed, the derived class interface conforms to the base class interface. This leads to...
3
1689
by: marv | last post by:
If I have abstract base classes like these: //--------- class IBase { public: virtual void Action(void) = 0; };
3
41520
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 am not clear on the disadvantages. I have had a look on the Web and in newsgroups but couldn't find much. As time is running out, I thought I would...
3
1171
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 articles on 2.0 but in practice it's behaving differently that I expected. I converted a backup copy of our corporate website to 2.0 and am seeing...
2
1462
by: Edd | last post by:
Hello all, Please consider: class Base { public: int pub; protected: int prot; private: int priv; };
0
2043
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 increment operator in a class and then defining a derived class and using the derived class. When I try to use the increment operator on an instance of...
2
2082
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: function A(){ var _this = this; this.a = 10;
4
3968
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 overrides both. Here is the code: class AA { public: class A {
11
2234
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 to illustrate this. Problem: I need to expose two lists of objects from a high-level class. I would like to expose these lists as read-only, but...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.