News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Where is the problem? My code? GCC? CodeBlocks?

Started by cecilio, January 15, 2013, 07:39:20 PM

Previous topic - Next topic

cecilio

I am debugging some code. Execution has arrived to this method:

void EventNotifier::notify_observers(SpEventInfo pEvent, Observable* target)
{
    std::list<Observer*>::iterator it;
    for (it = m_observers.begin(); it != m_observers.end(); ++it)
    {
        Observable* observedTarget = (*it)->target();
        bool fNotify = (observedTarget == target);
        ...

The last sentence of previous excerpt has been executed. Both variables, observedTarget and target, have the same value but boolean fNotify is false! (please see attached image)

I have no idea of were is the problem. Any help is greately appreciated. Thank you

Cecilio Salmeron
www.lenmus.org

[attachment deleted by admin]
Cecilio
www.lenmus.org

p2rkw


oBFusCATed

#2
Quote from: cecilio on January 15, 2013, 07:39:20 PM
I have no idea of were is the problem.
You've asked the question on the wrong forum... see the details in the rules http://forums.next.codeblocks.org/index.php/topic,9996.0.html
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

cecilio

To p2rkw:

Thank you that's a great clue. I do use inheritance. But both pointers are casted to Observable. How should I do it?


To oBFusCATed
Sorry! When I posted the question I thought it could be something related to Code::Blocks. And the description of the forum is "General (but related to Code::Blocks)
If your post doesn't fit any of the other topics, post it here :). This is NOT a general programming board.". Sorry again. Please, remove my post if not appropriate. Thank you.



Cecilio
www.lenmus.org

herrtool

You're comparing addresses, not values.  You mentioned the values are the same but you didn't mention the addresses.  This is a fairly common mistake (I've made it several times).  :)  Dereference the pointers (assuming Observable has an overloaded == operator).

P.S. - Yes, wrong forum but damage is done.  Hopefully this answer solves your problem (or better yet, you've figured it out already).

cecilio

Thank you for answering. I'm still fighting with this issue.

> P.S. - Yes, wrong forum but damage is done.

Sorry again. But I would appreciate a more positive feedback: where should i have posted this question?
Announcements? Not an announcement
Using Code::Blocks? Not a question about the usage of Code::Blocks
Embedded development? Nop
Nightly builds? Nop

So IMHO only two options:

Help [Code::Blocks installation/troubleshooting issues]
General (but related to Code::Blocks)

I thought that Help forum was perhaps more oriented to CB installation issues so I decided (wrongly, I see) to post to General forum. I thought that my problem could be some issue with Code::Blocks debugger.

Really, Which forum should I have used?

Never mind. Sorry for all the damage. Please delete this topic. Thank you.
Cecilio
www.lenmus.org

herrtool

I didn't mean to offend you.  I don't mind that you posted the question.  What I meant was that I was hoping that admins don't mind that I give you a pointer on your problem.


void EventNotifier::notify_observers(SpEventInfo pEvent, Observable* target)
{
    std::list<Observer*>::iterator it;
    for (it = m_observers.begin(); it != m_observers.end(); ++it)
    {
        Observable* observedTarget = (*it)->target();
        bool fNotify = (observedTarget == target);
        ...


replace


bool fNotify = (observedTarget == target);


with


bool fNotify = (*observedTarget == *target);


If you get a compiler error then you need to define a function that's visible to your function above.


bool operator==(const Observable& left, const Observable& right)
{
  return left.foo_member_data_stuff == right.foo_member_data_stuff;
}

p2rkw

@OP: Why you cast these pointers in watch window to lomse::lmoLink* ? Cast them to void* to see their real value. And don't use c style cast while using multiple inheritance. Use static_cast and dynamic_cast instead.

MortenMacFly

Topic locked as it violates the forum rules. Nevertheless, enough hints are given anyways...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]