different return value from same variable



Hi all,
I have a wierd C++/gtkmm problem. I have two functions which return the value of the same variable  - and produce different values for that variable. I'm guessing it's not a gtkmm problem, but I'm not sure. Please bear with me.

the details:

in ctx.h:   the header file for class Cnb, a sub-window for class Gui, which is a Gtk::Window.
Cnb contains both functions ( get_opmode & get_opmode2 ) and the variable ( _opmode ). e_opmode is the enum data type for _opmode.

    class Cnb   : public Gtk::Window
  {
  ...
  e_opmode  get_opmode () { return _opmode; }
  e_opmode  get_opmode2 ();
  ...
  e_opmode _opmode;   // current operation mode
  ...
  };

in ctx.cpp: the implementation file for ctx.h:

  ...
  e_opmode Cnb::get_opmode2 ()
    {
    return _opmode;
    }
  ...

in gui.cpp: a Gtk::Window (main window) class where CNB is declared,
After declaring CNB, I call the 2 functions which return the same variable ( _opmode ).

  Gui::Gui( bool is_sync)
  {
  ...
  CNB = new Cnb();
  std::cout << "gui 1: &CNB = " << &CNB << ", &_opmode = "
          << &CNB->_opmode << std::endl;
  std::cout << "gui 1: CNB->get_opmode2 = "
           << CNB->get_opmode2() << ", CNB->get_opmode = "
      << CNB->get_opmode() << std::endl;
    std::cout << "gui 1: &CNB = " << &CNB << ", &_opmode = "
          << &CNB->_opmode << std::endl;
  ...
  }

the following output results:

  ...
  gui 1: &CNB = 0x6d0a70, &_opmode = 0x94a460
  gui 1: CNB->get_opmode2 = 1, get_opmode = 19464624
  gui 1: &CNB = 0x6d0a70, &_opmode = 0x94a460
  ...

The correct value is '1'.
I get no errors on compilation or run-time. The addresses of CNB and _opmode isn't always the same for successive program tun, so it's not a RAM problem.
I've rebooted and re-strated emacs, with the same error.

Does anyone have a clue as to why I have different values for _opmode when using the 2 functions?
I'm completelly stumped.

I'm using:
  Fedora 14
  gcc-4.5.1-4
  Emacs 23.2-7
  gtkmm24-2.22.0-1

Thanks in advance for shedding some light on this.
Marty



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]