Results 1 to 2 of 2

Thread: header files problems

  1. #1
    Join Date
    May 2009
    Posts
    38
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default header files problems

    i have two classes A and B, i need them to have the access to each other.


    in file a.h:

    include "b.h"

    class A{

    private B *b;
    }

    in file b.h

    include "b.h"
    class B{

    private A *a;
    }



    compile give me the error said :

    1>A.cpp
    A: error C2143: syntax error : missing ';' before '*'
    A: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    A: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int


    2>B.cpp


    B: error C2143: syntax error : missing ';' before '*'
    B: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    B: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: header files problems

    You need forwart declarations:
    a.h:
    Qt Code:
    1. class B;
    2.  
    3. class A
    4. {
    5. private:
    6. B *b;
    7. };
    To copy to clipboard, switch view to plain text mode 
    b.h:
    Qt Code:
    1. class A;
    2.  
    3. class B
    4. {
    5. private:
    6. A *a;
    7. };
    To copy to clipboard, switch view to plain text mode 

    and then you don't include a.h in b.h but in b.cpp and b.h in b.cpp;
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. The following user says thank you to faldzip for this useful post:

    dognzhe (19th May 2009)

Similar Threads

  1. Replies: 4
    Last Post: 8th April 2010, 00:09
  2. A good system on header files
    By baray98 in forum General Programming
    Replies: 3
    Last Post: 23rd January 2009, 00:17
  3. Problems with scope and C header functions
    By waldowoc in forum Newbie
    Replies: 5
    Last Post: 5th August 2008, 12:29
  4. qt3 themes example: missing header files?
    By nikita in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2006, 13:12
  5. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 11:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.