Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

C++, Problem with List (insert)

zykyzyky Member Posts: 1
Hi all,
I'm trying to make a simple program: I need to create a class Blog, where Posts can be added. When a Post is added (Blog::newPost(Post p)) all Subscribers are Notifyed. I "eredited" 2 classes from Subscriber, which are notifyed in a different way.

Here is some code.

the postList and subscribersList:
[code] std::list elencoPost;
std::list elencoIscritti;[/code]

to add new posts I use:
[code]void Blog::newPost(Post ultimo) {

elencoPost.insert(elencoPost.end(),ultimo);
Notify(); // notify subscribers
}[/code]

main adds posts this way:
[code]blog_1.newPost(post_1);[/code]

and this works fine. so i made the same with the Subscriber (if you're asking why I use 2 methods, it was required by project specifications):
[code]void Subscriber::attach(Blog b) {

b.iscrizione(*this);
}

void Blog::iscrizione(Subscriber subs) {

elencoIscritti.insert(elencoIscritti.end(),subs);
}[/code]

the problem is that elencoIscritti (the List of Subscribers) does not "keep" the Subscriber I insert. for example:
- when in attach(Blog b) elencoIscritti.size() = 0;
- when in iscrizione(Subscriber s) elencoIscritti.size() = 1;
- when in main() elencoIscritti.size() = 0;

the List works fine with Post, but with Subscriber I have this problem.. :(

Any Idea?

thank you very much in advance




EDIT: solved. I needed:
list
instead of:
list

bye bye
Sign In or Register to comment.