DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2007
    Posts
    3

    help with makefile for a C++ code

    hi
    I instaniate object of one class in another and vice-versa. I get errors which seem to be because of dependencies not set right in makefile and the type is not available during instatniation.
    error: B.h: error: ISO C++ forbids declaration of ‘A’ with no type
    Please give me some suggestions

    Code:
    Makefile :
    
    OBJS = 	main.o A.o B.o
    
    .cpp.o:
    	g++ -g -Wno-deprecated -c $<
    
    
    run:	$(OBJS)
            g++ -g -Wno-deprecated -o $@ $(OBJS)
    
    
    main.o:	main.cpp 
    
    A.o:  A.cpp
    
    B.o:  B.cpp
    
    //header file A.h
    #ifndef _A_H_
    #define _A_H_
    
    #include "B.h"
    
    class A{
    
    A a; //object of class A
    B b;//object of class B
    
    void print(){}
    }
    
    #endif
    
    //cpp file A.cpp
    #include "A.h"
    
    void A::print(){
    cout << "A" << endl;
    }
    
    
    
    //header file B.h
    #ifndef _B_H_
    #define _B_H_
    
    #include "A.h"
    
    class B{
    
    A a;//object of class A
    B b;//object of class B
    
    }
    #endif
    
    //cpp file B.cpp
    #include "B.h"
    void B::print(){
    cout << "B" << endl;
    }
    regards
    Kiran
    Last edited by mpakala; 01-17-2007 at 04:56 PM. Reason: typo

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    Your declaration of class A contains a data member of the same type, A:

    class A{
    A a; //object of class A
    B b;//object of class B
    void print(){}
    }

    This is illegal in C++. A class can't have another instance of itself as a data member. Did you mean to declare a constructor perhaps? Or a pointer? Reference?
    Danny Kalev

  3. #3
    Join Date
    Jan 2007
    Posts
    3
    hi

    yes im sorry
    A* a;
    B* b;
    regards
    Kiran

Similar Threads

  1. wot is CLR
    By lostguy in forum .NET
    Replies: 8
    Last Post: 04-03-2002, 06:41 PM
  2. .NET equals Efficiency
    By Kevin in forum .NET
    Replies: 150
    Last Post: 03-04-2002, 05:40 PM
  3. Replies: 3
    Last Post: 07-09-2001, 03:25 PM
  4. Another Language
    By Steven Bell in forum .NET
    Replies: 260
    Last Post: 06-01-2001, 04:32 PM
  5. error code in JSP(please chek the code)
    By satish in forum Java
    Replies: 1
    Last Post: 09-22-2000, 09:11 AM

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
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links