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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gyre
    New Member
    • Sep 2007
    • 3

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

    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:

    [code=cpp]//ABSTRACT CLASS MEMBER:
    #ifndef _VCA_NODE
    #define _VCA_NODE

    #include <vca_net.h>
    #include <canmsg.h>

    #include <iostream>
    using namespace std;

    #include <QObject>

    class VcaNet;

    class VcaNode : public QObject
    {
    Q_OBJECT

    public:
    VcaNet *cannet;

    VcaNode(VcaNet *parent){
    this->cannet = parent;
    };
    virtual ~VcaNode() {cout <<"Node Has Been destroyed/disconnected"<< endl;};

    void emitSentSignal( int event_code, const canmsg_t *canmsg){
    emit sentMsg(event_c ode, canmsg);
    }

    virtual void connectNode() = 0;
    virtual int vcaSendMsgSeq(c anmsg_t *messages, int count) = 0;
    virtual int vcaRecMsgSeq(ca nmsg_t *messages, int count) = 0;

    signals:
    void sentMsg(int event_code, const canmsg_t *canmsg);

    public slots:
    virtual void nodeReady() = 0;

    };
    #endif[/code]


    Then I want to inherit it and override virtual methods ...So I created another class "VcaFdNode" that looks like this:
    [code=cpp]//INHERITED CLASS
    #ifndef _CAN_VCA_H
    #define _CAN_VCA_H

    #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;

    class VcaFdNode : public VcaNode
    {
    private:
    int vcah;

    int vcaWait(int wait_msec, int what);
    long vcaH2log();

    public:
    bool vca_ok;
    QSocketNotifier *sn;

    VcaFdNode(VcaNe t *_cannet, const char *dev_name/*, const char *options, int flags*/);
    ~VcaFdNode();

    void connectNode();//OK
    int vcaSendMsgSeq(c anmsg_t *messages, int count);//OK
    int vcaRecMsgSeq(ca nmsg_t *messages, int count);//OK

    int getVcaHandle();
    void setVcaHandle(in t handle);
    int vcaH2fd();

    public slots:
    void nodeReady();//OK

    };
    #endif[/code]

    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...
    Last edited by Ganon11; Sep 21 '07, 01:27 PM. Reason: Please use the [CODE] tags provided.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    [code=cpp]//ABSTRACT CLASS MEMBER:
    #ifndef _VCA_NODE
    #define _VCA_NODE

    #include <vca_net.h>
    #include <canmsg.h>

    #include <iostream>
    using namespace std;

    #include <QObject>

    class VcaNet;

    class VcaNode : public QObject
    {
    <snipped>
    };
    #endif[/code]

    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.


    [code=cpp]//INHERITED CLASS
    #ifndef _CAN_VCA_H
    #define _CAN_VCA_H

    #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;

    class VcaFdNode : public VcaNode
    {
    <snipped>
    };
    #endif[/code]

    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.

    Comment

    • gyre
      New Member
      • Sep 2007
      • 3

      #3
      Originally posted by Banfa
      [code=cpp]//ABSTRACT CLASS MEMBER:
      #ifndef _VCA_NODE
      #define _VCA_NODE

      #include <vca_net.h>
      #include <canmsg.h>

      #include <iostream>
      using namespace std;

      #include <QObject>

      class VcaNet;

      class VcaNode : public QObject
      {
      <snipped>
      };
      #endif[/code]

      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.


      [code=cpp]//INHERITED CLASS
      #ifndef _CAN_VCA_H
      #define _CAN_VCA_H

      #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;

      class VcaFdNode : public VcaNode
      {
      <snipped>
      };
      #endif[/code]

      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 :(

      Comment

      • gyre
        New Member
        • Sep 2007
        • 3

        #4
        Originally posted by gyre
        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 ;(

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Originally posted by gyre
          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.

          Comment

          • Turboente
            New Member
            • Sep 2007
            • 1

            #6
            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

            Comment

            Working...