I'm using Young's book on mixing C++ and Motif. In it, he says to use
XtGetSubresources() to be able to configure member data using the X
resource database. When I try this, based on Young's example,
class MyComponent: public UIComponent
{
...
private:
unsigned char _orientation
static XtResource _customResources[];
...
}
XtResource MyComponent::_customResources[]={
{
"orientation",
"Orientation",
XmROrientation,
sizeof(unsigned char),
XtOffsetOf(MyComponent,_orientation),
XmRString,
(XtPointer)"HORIZONTAL"
},{
...
}
};
I get compiler warnings about the above call to the XtOffsetOf()
macro.
% g++ -Wall -Wunused -W -ansi -pedantic -c MyComponent.C
MyComponent.C:116: warning: invalid offsetof from non-POD type
`class MyComponent'; use pointer to member instead
I understand the pointer to member syntax, but am not sure how to use
it here to appease the compiler. Is there a correct, portable, safe
way to do this?
Thanks,
Jim Williams 3 1917 ja**************@usa-spaceops.com wrote: I'm using Young's book on mixing C++ and Motif. In it, he says to use XtGetSubresources() to be able to configure member data using the X resource database. When I try this, based on Young's example,
[SNIP] I get compiler warnings about the above call to the XtOffsetOf() macro.
% g++ -Wall -Wunused -W -ansi -pedantic -c MyComponent.C MyComponent.C:116: warning: invalid offsetof from non-POD type `class MyComponent'; use pointer to member instead
I understand the pointer to member syntax, but am not sure how to use it here to appease the compiler. Is there a correct, portable, safe way to do this?
You cannot use offsetof: since you have a class which is not a POD. You
cannot use member pointers either, since you have a C interface, which has
no idea about member pointers. The best I could come up with is to create a
POD type and embed that one into your class. Register that thing using the
Motif functions.
--
WW aka Attila
On Mon, 22 Sep 2003 08:44:43 -0700, james.p.william wrote: I'm using Young's book on mixing C++ and Motif. In it, he says to use XtGetSubresources() to be able to configure member data using the X resource database. When I try this, based on Young's example,
class MyComponent: public UIComponent { ... private: unsigned char _orientation static XtResource _customResources[]; ... } } XtResource MyComponent::_customResources[]={ { "orientation", "Orientation", XmROrientation, sizeof(unsigned char), XtOffsetOf(MyComponent,_orientation), XmRString, (XtPointer)"HORIZONTAL" },{ ... } };
I get compiler warnings about the above call to the XtOffsetOf() macro.
% g++ -Wall -Wunused -W -ansi -pedantic -c MyComponent.C MyComponent.C:116: warning: invalid offsetof from non-POD type `class MyComponent'; use pointer to member instead
I understand the pointer to member syntax, but am not sure how to use it here to appease the compiler. Is there a correct, portable, safe way to do this?
class MyComponent : public UIComponent {
private:
struct Resources
{
unsigned char orientation_;
};
Resources res_;
static XtResource customResources_[];
};
XtResource MyComponent::customResources_[]= {
{
"orientation",
"Orientation",
XmROrientation,
sizeof(unsigned char),
XtOffsetOf(MyComponent::Resources, orientation_), XmRString,
(XtPointer)"HORIZONTAL"
}
};
(By the way, I prefer to use trailing underscores as it avoids potential
conflicts with identifiers reserved for use by implementors.) ja**************@usa-spaceops.com wrote: I'm using Young's book on mixing C++ and Motif. In it, he says to use XtGetSubresources() to be able to configure member data using the X resource database. When I try this, based on Young's example,
class MyComponent: public UIComponent { ... private: unsigned char _orientation static XtResource _customResources[]; ... }
XtResource MyComponent::_customResources[]={ { "orientation", "Orientation", XmROrientation, sizeof(unsigned char), XtOffsetOf(MyComponent,_orientation), XmRString, (XtPointer)"HORIZONTAL" },{ ... } };
I get compiler warnings about the above call to the XtOffsetOf() macro.
% g++ -Wall -Wunused -W -ansi -pedantic -c MyComponent.C MyComponent.C:116: warning: invalid offsetof from non-POD type `class MyComponent'; use pointer to member instead
I understand the pointer to member syntax, but am not sure how to use it here to appease the compiler. Is there a correct, portable, safe way to do this?
Yes ... and no.
Yes in the sense that C++ supports "pointer to member" types but No in
the sense that to do what Doug is doing here it will still be somewhat
non-portable.
I would find a way to silence the warning and live with it. A possible
way is to re-interpret cast a "pointer to member". If I'm not mistaken,
XtResource is defined in X Toolkit and you would have a helluva time
changing all the code that depends on that. This thread has been closed and replies have been disabled. Please start a new discussion. |