Re: Some questions about Gtk::TreeRow.



El Jun 20, 2010, a las 5:21 AM, sledge hammer <sledgehammer_999 hotmail com> escribió:

1. Is it possible/advisable to do something like this?

prototype function: foo(int *number);


struct bar
{
   int a;
   int b;
};

foo(&bar(row[columns.bar_struct]).a);

By constructing a bar struct from a bar struct obtained from a tree row, and then passing it's 'a' member by C reference (not C++ reference), modifying it in the foo function would be irrelevant because the constructed bar struct is only temporarily constructed and would disappear after the foo function returns.

You should construct the bar struct outside the invocation of foo() and pass that struct's 'a' member by reference.  That would ensure that the change made by foo() is remembered.


This compiles, but when I LATER check "bar(row[columns.bar_struct]).a" it hasn't changed. Is it possible to pass it by reference?


2. How about something like this:

struct bar
{
   int *a;
   int *b;
};

bar(row[columns.bar_struct]).a = new int;
*bar(row[columns.bar_struct]).a = 0;

This compiles but segfaults on *bar(row[columns.bar_struct]).a = 0;
Why can't I assign a value to data pointed by the pointer? Am I missing something on the dereferencing?

You are experiencing the same problem as above.  Really, two bar structs are constructed (one in the first line, another in the second).  Dereferencing the 'a' member of the second bar struct is a problem because it is null.

--
José


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