Thread: Mutual linking

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    41

    Unhappy Mutual linking

    Hi everybody!

    I have a short question about mutual linking (this is what I call it, I don't know if it's the right name...)

    I have 2 classes and they both have members of the type of the other class:

    //header.h

    class cls_one
    {
    cls_two * member;
    };

    class cls_two
    {
    cls_one * member;
    };

    obviously this doesn't compile, but this is the way I want to do it. Is there a way to do this?

    thanks

    Joren

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You need to put a forward declaration in your code so that cls_one knows about cls_two.

    Code:
    //header.h 
    class cls_two;
    
    class cls_one 
    { 
    	cls_two * member; 
    }; 
    
    class cls_two 
    { 
    	cls_one * member; 
    };

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    41
    Thanks! That worked

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems linking with g++
    By Just in forum Linux Programming
    Replies: 11
    Last Post: 07-24-2006, 01:35 AM
  2. strange linking error -- can not find shared library
    By George2 in forum C Programming
    Replies: 2
    Last Post: 07-10-2006, 10:51 PM
  3. Replies: 8
    Last Post: 04-27-2006, 10:39 AM
  4. Grrr.... SDL Linking Problem
    By 7EVEN in forum Game Programming
    Replies: 5
    Last Post: 08-12-2005, 08:44 PM
  5. Linking error with DirectDrawCreateEx
    By jjj93421 in forum Game Programming
    Replies: 6
    Last Post: 04-06-2004, 03:57 PM