User Tag List

Results 1 to 3 of 3

Thread: recursive classes references

  1. #1
    No Products Registered

    Join Date
    Jun 2007
    Location
    Croatia
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    recursive classes references

    Hi!

    I am making an extension and I have some problems

    i have two classes and four files:

    cMother.cpp, cMother.h, cSon.cpp and cSon.h...

    the classes are CMother and CSon.

    Now, the Mother should have

    CSon Sons[3];

    and the son should have a reference to the mother

    CMother *mother;

    The Son is created from mother's method and passed "this" which the son sets to its mother.

    The problem here is the obvious recursive relation between classes where one should be declared before the other and vice versa.

    Is there any way to make this work?

    I am more of a C# programmer, so I have some difficulties returning to C++ since C# doesn't care which is declared first...

    thank you.

  2. #2
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: recursive classes references

    As the CMother class contains actual instances of the CSon class, CSon must be declared first so that the compiler knows how big CMother is. Because the CSon class only contains a pointer to CMother, just declare it as "class CMother *mother" to let C++ know that "CMother" is a class and not a coding error. All class pointers are the same size, so it doesn't need the actual definition of the CMother class until you try to use the pointer.

    In C# all class variables are actually only references to the class, so it doesn't need to know the size of the class, only the size of a reference to a class.

  3. #3
    No Products Registered

    Join Date
    Jun 2007
    Location
    Croatia
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: recursive classes references

    thanks for quick response.

    I knew that there must be a simple solution to this since CSon only contains a pointer to CMother, but didn't know how to make it work.

    I tried declaring
    class CMother; above CSon but didn't work...

    This however works.
    Thank you again.

Similar Threads

  1. DotNet - FileNotFound - References
    By ShadowLord1 in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 4th August 2013, 03:23 AM
  2. Object classes in XLua
    By Ibis in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 2nd June 2013, 10:23 PM
  3. Specific place for Classes in rSDK?
    By Iwantmyrpg in forum Extension Development
    Replies: 8
    Last Post: 4th July 2010, 06:46 PM
  4. Recursive File Returns
    By JJames19119 in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 23rd October 2006, 05:32 AM

Posting Permissions

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