Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2006

Tip: Looking for answers? Try searching our database.

Cyrcle reference problem...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MilanB - 22 Jul 2006 21:50 GMT
Hello

I have struct, and class that handle array of previous mentioned structs.
How to declare struct member, that will point to class that it belongs?

struct S
{
//HOW TO ADD MEMBER THAT WILL POINT TO CLASS C ???
}

class C
{
S** items;
}

Thanks
Milan
Carl Daniel [VC++ MVP] - 22 Jul 2006 22:52 GMT
> Hello
>
[quoted text clipped - 11 lines]
> S** items;
> }

You need to use a "forward declaration":

class C;

struct S
{
   C* m_c;    // you can use C* or C&, but not just C
};

class C
{
   S** items;
};

-cd
MilanB - 23 Jul 2006 07:00 GMT
Thanks Daniel.
You solved my problem succesfully.

I would like to you ask about situation that I want to have memeber in
struct S, that point to function in class C (not whole class) does it changes
situation? (All other are the same)

struct S
{
//POINTER TO CLASS C MEMBER FUNCTION: IncrementSelectedCount()
};

class C
{
S** items;
private: int selectedCount;
private: void incrementSelectedCount(void)
  {
        selectedCount++;
  }
};

> > Hello
> >
[quoted text clipped - 27 lines]
>
> -cd
MilanB - 23 Jul 2006 11:07 GMT
OK. I Found it.
For other who maybe need same help here is solution:

class MyClass;    //Forward declaration

//========================================

struct MyStruct
{
private: MyClass *myClass;    
private: void (MyClass::*ptrToMemFunction)();
public:  void CallFunction()
    {
        //Calling member function from referenced class
        (myClass->*ptrToMemFunction)();
    }

//On costructor pass Class and Function Member pointer
public :MyStruct(MyClass *parMyClass, void (MyClass::*parPtrToMemFunction)())
    {
        MyStruct::myClass = parMyClass;
        MyStruct::ptrToMemFunction = parPtrToMemFunction;
    }

//========================================

class MyClass
{
private:    void memberFunction(void)
    {
        //do something   
    }

//Pass references..
private:    void addNew(...) //some function...
    {
.
.
.
        void (MyClass::*ptrToMemberFunction)() = memberFunction;
        MyStruct myStruct = new MyStruct(this, ptrToMemberFunction);
        //Now we have struct that have valid pointer to MyClass::memeberFunction
.
.
    }

};

Regards
Milan

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.