From: Peter Sippel <[email protected]> - 8 Mar 1999
I want to declare a c4_RowRef member variable, which will be set from another class.
class myClass { private: c4_RowRef _row; }
The compiler (Power++ 2.1) comes up with an error:
"cannot generate default constructor to initialize '%T' since constructors were declared"
Reply:
That's intentional. It is exactly the same behavior as for say
int& _int;
The way around this is to use c4_Cursor instead.
OOPS. There's a very unfortunate problem here. The c4_Cursor class *also* does not allow default initializers (for a different reason).
Hmm. You'll have to use a workaround. Define a static row:
static c4_Row dummyRow;
Then use c4_Cursor objects:
c4_Cursor _cursor;
And initialize in the default constructor as:
myClass::myClass() : _cursor (&dummyRow) {}
Then you can alter _cursor later. And use (*_cursor) instead of _row.
Yes, this is messy. The reasoning is the same as with references versus pointers: "rowref = row" will *copy* data, while "cursor = &row" only changes the way a cursor is pointing.
These important issues will all be addressed in the next major release of Metakit. It's things like these which make it harder to use than is really necessary.
Here's another suggestion (untested). Derive a class from c4_Cursor, which adds a default constructor, and sets the cursor as above. If you don't want to use static objects, or cannot, there are ways around it. Then, you can keep your code clean, by switching to cursor, and defining them as follows (and get rid of the need to initialize them everywhere):
my_Cursor _cursor;
-- JC