473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Pointer back to a specific instance.

Hi,

I want to find out the best "C++" way to do this:

I have 2 classes:

class IHost:
{

static callback(..)
}
and
#include "IHost.h"
class PluginManager:
{
....

protected:
IHost m_IHost;
}
For one function, the IHost class has to signal back to the
PluginManager class that the plugin has signalled a status change.
Before I get into what I tried, I want to first ask, what is the
proper "C++ way" of doing such a circular reference? Friend class?

Anyway, I tried this:

#include "PluginManager.h"
class IHost:
{
IHost ( PluginManager *ptr )
{
m_pPluginManager = ptr;
}

static callback(..)

protected:
PluginManager *m_pPluginManger
}
and
#include "IHost.h"
class PluginManager:
{
....

protected:
IHost m_IHost;
}

However, my compiler still won't recognize PluginManager as a class in
the IHost class definition. I've had a problem in the past that if I
try to include in a class a class that is already including that class
(like the example directly above), the compiler barfs in C++.

My next thought was to try a friend class definition, but then I
figrued I would try and find out the proper way to do this.

Thanks for any feedback in advance.

T
Dec 29 '07 #1
2 1043
Nevermind, I think I figured it out:

class PluginManager;

class IHost:
{
IHost ( PluginManager *ptr )
{
m_pPluginManager = ptr;
}
static callback(..)
protected:
PluginManager *m_pPluginManger

}
and

#include "IHost.h"
class PluginManager:
{
....
protected:
IHost m_IHost;

}
Dec 29 '07 #2
On Dec 29, 12:01 pm, TBass <t...@automateddesign.comwrote:
Hi,

I want to find out the best "C++" way to do this:

I have 2 classes:

class IHost:
{

static callback(..)

}

and

#include "IHost.h"
class PluginManager:
{
....

protected:
IHost m_IHost;

}

For one function, the IHost class has to signal back to the
PluginManager class that the plugin has signalled a status change.
Before I get into what I tried, I want to first ask, what is the
proper "C++ way" of doing such a circular reference? Friend class?

Anyway, I tried this:

#include "PluginManager.h"
class IHost:
{
IHost ( PluginManager *ptr )
{
m_pPluginManager = ptr;
}

static callback(..)

protected:
PluginManager *m_pPluginManger

}

and

#include "IHost.h"
class PluginManager:
{
....

protected:
IHost m_IHost;

}

However, my compiler still won't recognize PluginManager as a class in
the IHost class definition. I've had a problem in the past that if I
try to include in a class a class that is already including that class
(like the example directly above), the compiler barfs in C++.
it should barf
>
My next thought was to try a friend class definition, but then I
figrued I would try and find out the proper way to do this.

Thanks for any feedback in advance.

T
Its always helpfull if you post compileable code, even if its toy
code.
Use initialisation lists in your constuctors, other languages would
kill to have them.
Your problem involves forward declarations:

// forward declaration
class PluginManager;

class IHost
{
PluginManager* m_pPluginManger;
public:
IHost(PluginManager* ptr) : m_pPluginManger(ptr)
{
}
static void callback() { }
};

class PluginManager
{
public:
PluginManager() : m_IHost(this)
{
}
protected:
IHost m_IHost;
};

int main()
{
PluginManager pm;
}

As far as callbacks are concerned, take a look at Boost.bind,
Boost.Function
Dec 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

79
by: syntax | last post by:
what is the size of a pointer? suppose i am writing, datatype *ptr; sizeof(ptr); now what does this sizeof(ptr) will give? will it give the size of the
11
by: Sushil | last post by:
Hi Gurus I've tried to come up with a small logical example of my problem. The problem is platform specific (MIPS) which I understand should not be discussed here. So here goes my example: ...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
2
by: Edward Diener | last post by:
How does one specify in a component that a property is a pointer to another component ? How is this different from a property that is actually an embedded component ? Finally how is one notified in...
8
by: nsharma78 | last post by:
Hi, I have a code as follows: class A { public: void print(){cout << "Magic" << endl;} };
27
by: Erik de Castro Lopo | last post by:
Hi all, The GNU C compiler allows a void pointer to be incremented and the behaviour is equivalent to incrementing a char pointer. Is this legal C99 or is this a GNU C extention? Thanks in...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
14
by: shaanxxx | last post by:
int main() { int *i = (int *) &i; } Above statement is a valid statement as per standard ? Since object is getting created and same time i am trying to store its address in itself, it is...
18
by: Stephan Beal | last post by:
Hi, all! Before i ask my question, i want to clarify that my question is not about the code i will show, but about what the C Standard says should happen. A week or so ago it occurred to me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.