Thread: 2 Classes Accessing Eachother

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    47

    2 Classes Accessing Eachother

    Alright I am writing a program that I need to give it the ability to have 2 seperate classes access eachother for example...
    say I have class CUser and CChannel
    they would look like this
    Code:
    class CUser
    {
    public:
     CChannel *ChannelList;
    //functions here
    }
    and in a separate file I would have another class like this
    Code:
    class CChannel
    {
    public:
    CUser *UserList;
    //functions here
    }
    now if I try to include them to eachother with an ifndef in it so they do not go into an infinate loop it still doesnt declare them properly. Is there a way that I can get my classes to access eachother like this. Please help me out. and my main function by the way would pass the reference to each class

  2. #2
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    put prototypes of the other class above the class that access another (especially if it's in a different file)

    ex:
    Code:
    class CChannel;
    class CUser
    {
    public:
     CChannel *ChannelList;
    //functions here
    }
    -LC
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    47
    I think I might have just found a way guys...nevermind

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing classes
    By Mavix in forum C# Programming
    Replies: 2
    Last Post: 02-16-2008, 09:43 PM
  2. Help accessing classes and derived classes
    By hobbes67 in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2005, 02:46 PM
  3. Accessing main form from functions in other classes
    By pj_martins in forum C++ Programming
    Replies: 1
    Last Post: 11-05-2004, 09:27 AM
  4. Replies: 8
    Last Post: 07-27-2003, 01:52 PM
  5. Accessing Classes in Classes
    By GrNxxDaY in forum C++ Programming
    Replies: 18
    Last Post: 07-30-2002, 01:54 PM