Re: Referencing the container object
On Feb 4, 1:38 am, "Alf P. Steinbach" <al...@start.no> wrote:
* Alessandro [AkiRoss] Re:
Confusion of compile time and run time.
Yes, of course. I wrote it as a suggestion (in the case it could be
useful :D)
Either design is bad, or you should be able to just iterate. E.g.
class Container;
class User
{
public:
User( Container& ) {}
};
class Container
{
private:
std::vector<User> myUsers;
public:
Container() : myUsers( 42, *this ) {} // 42 User in=
stances.
};
How can I do this?
See above.
Cheers & hth.,
- Alf
No, it shouldn't iterate.
Actually, the User objects are functors and need to be accessed with
the name specified by the user... E.g.
struct Functor { void operator()() { /* blah */ } }
struct UserContainer : public MyContainer {
Functor method;
} cont;
cont.method();
Too bad, I'm not an expert about design, but I'm trying to implement
this code to be usable by future programmers.
And well, functors used like these is pretty straightforward.
In addition, the functor must be registered in the container object...
If I don't find an automagic way of doing this, the user must do it,
and it's more error prone.
Thanks anyway :) I'll try to consider other approaches.