×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    39

    include header file error.

    hi.all
    i have class A,B and C.
    in file A.h i have
    #include "A.h"
    #include "B.h"
    #include "C.h"

    in file B.h i want to add #include "A.h"
    compile error it show msg. undefined identifier 'B' in class A at line
    B *b;

    How do i do?
    Thank you

  2. #2
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,359

    Re: include header file error.

    If your class A has a member that points to B you do not need to include b.h, a forward declaration of class B would be enough.

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    39

    Re: include header file error.

    it still error.
    in A.h
    #include "A.h"
    class A
    {
    B *b;
    C *c;
    };

    in B.h
    #include "B.h"
    #include "A.h"
    class B
    {
    A *a;
    };

    How do i do?

  4. #4
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,359

    Re: include header file error.

    in A.h

    Code:
    #ifndef __A_H__
    #define __A_H__
    
    class B;
    class C;
    
    class A
    {
    B *b;
    C *c;
    };
    
    #endif
    in B.h:

    Code:
    #ifndef __B_H__
    #define __B_H__
    
    class A;
    
    class B
    {
    A *a;
    };
    
    #endif

  5. #5
    Registered User
    Join Date
    Jul 2006
    Posts
    39

    Re: include header file error.

    Oh ,it not error at file.h but it error at file.cpp

    Code:
    #include "AMainGame.h"
    
    A* A::NewL()
    {
    	CAMainGame* self=CAMainGame::NewLC();
    	CleanupStack::Pop();
    	return self;
    }
    A* A::NewLC()
    {
    	CAMainGame* self=new(ELeave) CAMainGame();
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	return self;
    }
    void A::ConstructL()
    {	
    	B= new (ELeave) B();
            C= new (ELeave) C();
    }
    A:: ~A()
    {
    	delete Town;
            delete Bat;
    }
    it show msg. error illigel use of incompete struct/union/class 'B'
    illigel use of incompete struct/union/class 'A'
    at that line orange.

    How do i do?

  6. #6
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,359

    Re: include header file error.

    You need to include the declarations of B and C's constuctors otherwise the compiler cannot instantiate the objects.

    Code:
    #include "AMainGame.h"
    
    #include "b.h"
    #include "c.h"
    
    
    A* A::NewL()
    {
    	CAMainGame* self=CAMainGame::NewLC();
    	CleanupStack::Pop();
    	return self;
    }
    A* A::NewLC()
    {
    	CAMainGame* self=new(ELeave) CAMainGame();
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	return self;
    }
    void A::ConstructL()
    {	
            B= new (ELeave) B();
            C= new (ELeave) C();
    }
    A:: ~A()
    {
    	delete Town;
            delete Bat;
    }
    You also need a C/C++ book

Similar Threads

  1. Recording in Amr Format
    By losym in forum Symbian Media (Closed)
    Replies: 12
    Last Post: 2009-03-26, 06:41
  2. Carbide.vs 2.01 Registration Problem
    By baykal in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2006-12-22, 16:55
  3. Problem to compile series60 3rd
    By asmobease in forum Symbian
    Replies: 9
    Last Post: 2006-09-04, 15:15
  4. Dialogs within Symbian 6.0 based SDK
    By georgica1979 in forum Symbian User Interface
    Replies: 14
    Last Post: 2003-04-07, 15:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×