D
danny van elsen
hello all,
I don't understand the implications of the 'const' keyword in the
following...
I have a class
class util::Utilities
{
public:
.... usual stuff ...
string int_to_hexstring(int i);
}
and an other class (building on the gnome gtkmm class hierarchy)
class dis::gui::Gui_TreeModel
: public Glib::Object,
public Gtk::TreeModel
{
public:
.... usual stuff ...
protected:
virtual void get_value_vfunc(const TreeModel::iterator& iter, int column,
Glib::ValueBase& value) const;
private:
util::Utilities u;
}
inside the function
void
dis::gui::Gui_TreeModel::get_value_vfunc(const TreeModel::iterator& iter, int column, Glib::ValueBase& value) const
I cannot put :
std::string result_string;
result_string = u.int_to_hexstring(dn->memory_offset);
because this gives the error
passing `const util::Utilities' as
`this' argument of `std::string util::Utilities::int_to_hexstring(int)'
discards qualifiers
however, this works:
std::string result_string;
util::Utilities u2;
result_string = u2.int_to_hexstring(dn->memory_offset);
- I don't understand the difference between the two? why is one version
legal, while the other isn't?
greetings, Danny.
I don't understand the implications of the 'const' keyword in the
following...
I have a class
class util::Utilities
{
public:
.... usual stuff ...
string int_to_hexstring(int i);
}
and an other class (building on the gnome gtkmm class hierarchy)
class dis::gui::Gui_TreeModel
: public Glib::Object,
public Gtk::TreeModel
{
public:
.... usual stuff ...
protected:
virtual void get_value_vfunc(const TreeModel::iterator& iter, int column,
Glib::ValueBase& value) const;
private:
util::Utilities u;
}
inside the function
void
dis::gui::Gui_TreeModel::get_value_vfunc(const TreeModel::iterator& iter, int column, Glib::ValueBase& value) const
I cannot put :
std::string result_string;
result_string = u.int_to_hexstring(dn->memory_offset);
because this gives the error
passing `const util::Utilities' as
`this' argument of `std::string util::Utilities::int_to_hexstring(int)'
discards qualifiers
however, this works:
std::string result_string;
util::Utilities u2;
result_string = u2.int_to_hexstring(dn->memory_offset);
- I don't understand the difference between the two? why is one version
legal, while the other isn't?
greetings, Danny.