How to call back?

T

thomas

Hi guys,

------------------------------------------------------------------
struct Item{
int i;
};

class Child(){
void dosth(){
for (int i = 0; i < 100; ++i)
{
Item* newItem = new Item();
Parent.push(newItem); //A
}
}
}

class Parent{
public:
void push(Item* p){
VecItem.push_back(p);
}
vector<Item*> VecItem;
Child* pChild;
};
-----------------------------------------------------------------

How to modify line A to make it work correctly and elegantly?
1. I don't want to pass vectors between classes
2. I infer if something like allocator can make it work.
3. I don't want to expose the whole class Parent to Child, because
there are many other interfaces that Child doesn't need.
 
V

Vaclav Haisman

thomas wrote, On 12.5.2011 4:43:
Hi guys,

------------------------------------------------------------------
struct Item{
int i;
};

class Child(){
void dosth(){
for (int i = 0; i < 100; ++i)
{
Item* newItem = new Item();
Parent.push(newItem); //A
}
}
}

class Parent{
public:
void push(Item* p){
VecItem.push_back(p);
}
vector<Item*> VecItem;
Child* pChild;
};
-----------------------------------------------------------------
Please try to make a "working" example. Yours contains several syntactic
errors. It is not clear what is the intention of the code and what is the
real error.
How to modify line A to make it work correctly and elegantly?
1. I don't want to pass vectors between classes
2. I infer if something like allocator can make it work.
I do not understand this.
3. I don't want to expose the whole class Parent to Child, because
there are many other interfaces that Child doesn't need.
Try using pure virtual functions and "interface" classes to expose only the
necessary interface of Parent to Child.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top