Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. <solved> Errors: C2143, C4430 but it is included
Forum Updated to NodeBB v4.3 + New Features

<solved> Errors: C2143, C4430 but it is included

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 5.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    huckfinn
    wrote on last edited by
    #1

    I got the error above for following code:
    @
    // A.cpp:
    #include "A.h"
    #include "B.h"

    A::A( B &ref_b)
    : b( ref_b )
    {}

    void A::create_T()
    { t = new T(); }
    //EOF

    // A.h:
    #ifndef A_H
    #define A_H

    #include "T.h"
    #include "B.h"

    class A {
    public:
    A( B &b);
    ~A();
    void create_T();

    private:
    B &b;
    T *t;
    };
    #endif //EOF

    // B.cpp:
    #include "B.h"
    #include "A.h"

    B *B::m_pInstance = NULL;

    B::B( void )
    {}

    B *B::GetInstance()
    {
    if( !m_pInstance )
    {
    m_pInstance = new B();
    }
    return m_pInstance;
    }
    // EOF

    //B.h:
    #ifndef B_H
    #define B_H

    #include "A.h"

    class B : public QThread
    {
    public:
    B( void );
    virtual ~B( void );
    static B *GetInstance();

    private:
        A *a;
        static B *b; 
    

    };
    #endif
    // EOF

    // T.cpp:
    #include "T.h"
    #include <iostream>

    using namespace std;

    T::T()
    {
    this->ptr_Special = NULL;

    void T::acceptConnection()
    {}

    void T::startRead()
    {}
    // EOF

    //T.h:
    #ifndef T_H
    #define T_H

    #include "A.h"

    class T: public QObject
    {
    public:
    T();
    ~T();

    public slots:
    void acceptConnection();
    void startRead();

    private:
    A *ptr_Special;
    };
    #endif //EOF
    @

    When I have ptr_Special locally in a method, instead of in the Header, I can compile that stuff..

    Any suggestions?

    Cheers Huck

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrtc3
      wrote on last edited by
      #2

      Seem like your code is including each other recursively.
      I recommend to use forward deklarations, to prevent circular includes in header files.

      hth!

      There are 10 types. Those who understand binary and those who don't .)

      1 Reply Last reply
      0
      • H Offline
        H Offline
        huckfinn
        wrote on last edited by
        #3

        Thank you, I included the corresponding headers in one Class and then I forwarded the required class' in the other classes.. But in T.cpp for e.g. @ptr_Special->callMethod();@ then I further get an:

        C2027: use of undefined type 'A'
        C2227: left of '->callMethod' must point to class/struct/union/generic type

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrtc3
          wrote on last edited by
          #4

          You forward-declared the A class, which only declares pointers of that type within your class T. Since pointers all have the same size this is ok. Here, you are attempting to use the class A, by calling callMethod(), without actually defining what A is. Something like:@A *ptr_Special = new A();@

          When it comes to using this class the compiler has to know more about the A class, at least its size. Unfortunately, no information is accessible other than that there is a class called A. So I would recommend you put #include statements for the already forwarded class A in class T's source T.cpp.

          --> forward declaration in the T.h : class A; // to prohibit circling includes
          --> accordingly include in its T.cpp: #include "A.h" // to tell the pointers required space

          --------> Correspondingly for all the other forward declared classes, too.

          hth!

          There are 10 types. Those who understand binary and those who don't .)

          1 Reply Last reply
          0
          • H Offline
            H Offline
            huckfinn
            wrote on last edited by
            #5

            That has solved it, thanks!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved