By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

Returning a non-pod object

P: n/a
Hallo,

I am searching for helpü with non-pod objects. I have a class X which
contains an object y of class Y as a member. This object is non-pod. Now I
have an object x from class X and want to isolate the object y out of it. I
tried it with adding a get-fucntion.

Y X::getObjectY(void)
{
return y;
}

In my main program I create an Y object where I want to store the result of
that function.

Y myy;
....
myy = x->getObjectY();

Now gcc (I use Fedora Core 2.0) plays wild boar and comes with an error
message like this: "object y is non-pod. assignment will be aborted during
runtime". In result I dont have y copied in myy. But that is what I want
because I want to send myy over a network.

Does anyone had this problem before and know how to solve it.

Many thanks
Jan
Jul 23 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Jan-Henrik Grobe wrote:
I am searching for helpü with non-pod objects. I have a class X which
contains an object y of class Y as a member. This object is non-pod. Now I
have an object x from class X and want to isolate the object y out of it. I
tried it with adding a get-fucntion.

Y X::getObjectY(void)
{
return y;
}

In my main program I create an Y object where I want to store the result of
that function.

Y myy;
...
myy = x->getObjectY();
Have you tried doing initialisation instead of assignment? Like

Y myy(x->getObjectY());

?
Now gcc (I use Fedora Core 2.0) plays wild boar and comes with an error
message like this: "object y is non-pod. assignment will be aborted during
runtime". In result I dont have y copied in myy. But that is what I want
because I want to send myy over a network.

Does anyone had this problem before and know how to solve it.


You would have to post the definition of Y to begin with.

V
Jul 23 '05 #2

P: n/a

"Victor Bazarov" <v.********@comAcast.net> schrieb im Newsbeitrag
news:ex*******************@newsread1.mlpsca01.us.t o.verio.net...
Jan-Henrik Grobe wrote:
I am searching for helpü with non-pod objects. I have a class X which
contains an object y of class Y as a member. This object is non-pod. Now
I have an object x from class X and want to isolate the object y out of
it. I tried it with adding a get-fucntion.

Y X::getObjectY(void)
{
return y;
}

In my main program I create an Y object where I want to store the result
of that function.

Y myy;
...
myy = x->getObjectY();


Have you tried doing initialisation instead of assignment? Like

Y myy(x->getObjectY());

?

Hallo,

may thanks....the only problem is, that the assignment has to be done
continously in a callback function.

Jan
Jul 23 '05 #3

P: n/a
Jan-Henrik Grobe wrote:
[..] the only problem is, that the assignment has to be done
continously in a callback function.


Well, fine. What about my suggestion on posting the definition of 'Y'?

V
Jul 23 '05 #4

P: n/a

"Victor Bazarov" <v.********@comAcast.net> schrieb im Newsbeitrag
news:kr*******************@newsread1.mlpsca01.us.t o.verio.net...
Jan-Henrik Grobe wrote:
[..] the only problem is, that the assignment has to be done continously
in a callback function.


Well, fine. What about my suggestion on posting the definition of 'Y'?

V

Hallo,

Y looks like this

class Y

{

public:

void clear();

bool MouseEvent () const { return v_event==1; }

bool MouseMove () const { return (v_event==1 && v_v0.i0()==0); }

bool MousePush () const { return (v_event==1 && v_v0.i0()==1); }

bool MouseDrag () const { return (v_event==1 && v_v0.i0()==2); }

bool MouseRelease () const { return (v_event==1 && v_v0.i0()==3); }

bool MouseDblClick() const { return (v_event==1 && v_v0.i0()==4); }

bool MouseLButton () const { return (v_event==1 && v_v1.i0()==1); }

bool MouseRButton () const { return (v_event==1 && v_v1.i0()==2); }

bool MouseMButton () const { return (v_event==1 && v_v1.i0()==3); }

bool KeyEvent () const { return v_event==2; }

bool KeyShift () const { return ((v_v2.i1()&1)==1); }

bool KeyCtrl () const { return ((v_v2.i1()&2)==2); }

bool KeyAlt () const { return ((v_v2.i1()&4)==4); }

bool Spacemouse () const { return v_event==3; }

bool SelectHit () const { return v_selectHit; }

// *** Event custom data

int v_event;

Token v_v0, v_v1, v_v2, v_v3;

// *** possibly additionally a select

bool v_selectHit;

Token v_pNear; // Mouse on near plane

Token v_pFar; // Mouse on far plane

Token v_hitpoint; // hit point,

Token v_screenXY; // Mouse event, pixel coords

Token v_hittoken; // registered object

Token v_ticket; // HandleIO ticket for the hit

};

it contains geometrical events....the object has to be send through a
network, because these events (the resulting rendering) have to be performed
on the client computers

Hope that helps

Jan
Jul 23 '05 #5

P: n/a
Jan-Henrik Grobe wrote:
"Victor Bazarov" <v.********@comAcast.net> schrieb im Newsbeitrag
news:kr*******************@newsread1.mlpsca01.us.t o.verio.net...
Jan-Henrik Grobe wrote:
[..] the only problem is, that the assignment has to be done continously
in a callback function.
Well, fine. What about my suggestion on posting the definition of 'Y'?

V


Hallo,

Y looks like this

class Y

{

public:

[.. member functions ..]
// *** Event custom data

int v_event;


OK, no problem assigning 'int'.

Token v_v0, v_v1, v_v2, v_v3;
What's "Token"? Is 'Token' assignable?

// *** possibly additionally a select

bool v_selectHit;
No problem here either.

Token v_pNear; // Mouse on near plane
[.. more Token objects ..]
Again, is 'Token' assignable?

};

it contains geometrical events....the object has to be send through a
network, because these events (the resulting rendering) have to be performed
on the client computers


That's irrelevant AFA C++ is concerned.

You see, if the compiler complains about being unable to perform the
operation "assignment", you need to start looking at the involved types
trying to understand how assignment is going to be attempted and why it
might fail. Could it be that the operator= is a virtual function and is
declared pure? Although that would make objects non-instantiable...

Anyway, impossible to conclude at this point (yet). Extract your classes
into a separate project, reduce to the bare minimum that still exhibits
the problem, perhaps in the process you'll find the cause, if not, post
the bare minimum code here, we'll take a look at it again.

V
Jul 23 '05 #6

P: n/a

"Victor Bazarov" <v.********@comAcast.net> schrieb im Newsbeitrag
news:LW*******************@newsread1.mlpsca01.us.t o.verio.net...
Jan-Henrik Grobe wrote:
"Victor Bazarov" <v.********@comAcast.net> schrieb im Newsbeitrag
news:kr*******************@newsread1.mlpsca01.us.t o.verio.net...
Jan-Henrik Grobe wrote:

[..] the only problem is, that the assignment has to be done continously
in a callback function.

Well, fine. What about my suggestion on posting the definition of 'Y'?

V


Hallo,

Y looks like this

class Y

{

public:

[.. member functions ..]
// *** Event custom data

int v_event;


OK, no problem assigning 'int'.

Token v_v0, v_v1, v_v2, v_v3;


What's "Token"? Is 'Token' assignable?

// *** possibly additionally a select

bool v_selectHit;


No problem here either.

Token v_pNear; // Mouse on near plane
[.. more Token objects ..]


Again, is 'Token' assignable?

};

it contains geometrical events....the object has to be send through a
network, because these events (the resulting rendering) have to be
performed on the client computers


That's irrelevant AFA C++ is concerned.

You see, if the compiler complains about being unable to perform the
operation "assignment", you need to start looking at the involved types
trying to understand how assignment is going to be attempted and why it
might fail. Could it be that the operator= is a virtual function and is
declared pure? Although that would make objects non-instantiable...

Anyway, impossible to conclude at this point (yet). Extract your classes
into a separate project, reduce to the bare minimum that still exhibits
the problem, perhaps in the process you'll find the cause, if not, post
the bare minimum code here, we'll take a look at it again.

V

Hey,

Token is another with assignable and unassignable objects. I must say, that
I havent written the Token-class and the Y-class by myself and they cannot
be changed. My job is only to "copy out" the Y-object out of the X-object
and send it over the net to "paste it in" the X-object that is running on
the client PC. I dont know...maybe it is possible to get the pointer from
the y-object and create a new y-object in the main application and assign
the value behind the pointer to that new object

Greetings
Jan
Jul 23 '05 #7

P: n/a

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:LW*******************@newsread1.mlpsca01.us.t o.verio.net...

it contains geometrical events....the object has to be send through a
network, because these events (the resulting rendering) have to be
performed on the client computers


That's irrelevant AFA C++ is concerned.


I'm wondering if that actually *is* relevant in this case. He's mentioned
several things that suggest he's dealing with an issue that isn't standard
C++. For one, the error message says that the assignment will be aborted
"at run time". That's not any normal C++ error I've ever heard of. And he
says he can't do initialization, because he's required to "continuously
assign" it in a callback function.

I'm suspecting that he's using a compiler that is somehow aware of the
networked nature of this software, and is telling him that non-POD objects
cannot be copied, **at run time**, in this manner. That's probably because
there's no way to allocate the shared memory (or whatever) that is used to
get the data from the server object to the client object.

If that's the case, then what he needs is to either make proper use of the
network facilities for a non-POD object (a subject only addressable by the
reading the docs for that software or that networking system, or by asking
on a more appropriate newsgroup), or else the object needs to return some
kind of POD representation of the actual data (such as by streaming it into
an array of char), which *can* be passed using this system.

I'm only guessing here, but that sounds like what he's trying to do, to me
anyway. (And I think it's off-topic here, and should be taken to a
newsgroup that knows what he's talking about.)

-Howard


Jul 23 '05 #8

P: n/a
Jan-Henrik Grobe wrote:
[..]
Token is another with assignable and unassignable objects.
If that's so, then Token may not be assignable, and that's your problem.
I must say, that
I havent written the Token-class and the Y-class by myself and they cannot
be changed.
That's too bad.
My job is only to "copy out" the Y-object out of the X-object
and send it over the net to "paste it in" the X-object that is running on
the client PC.
I am not blaming you or trying to make you do what you don't want to.
I dont know...maybe it is possible to get the pointer from
the y-object and create a new y-object in the main application and assign
the value behind the pointer to that new object


It seems that what you're solving here is a *serialization* problem. You
need to send information over the wires, which should represent the 'Y'
object in such way that it can be recreated. Without knowing the problem
domain in detail (not that I'm asking you to fill me in) it is difficult
to give you more specific advice than the following. Try to imagine what
information you need to be able to recreate a 'Y' on the other end of your
transmission and stick it into your other 'X'. Perhaps you need to make
up another type, like 'Y_proto', which will be created by your 'X', then
transmitted somehow and then used by the other 'X' to generate the proper
'Y' object inside it. You do have control over 'X', don't you?

In some cases you can get away with some binary content, especially if you
do not cross platform borders, in other instances you need to convert your
internal representations into some kind of text stream, formed on one end
and interpreted at the other end. I don't know which you'll pick, nor do
I claim the ability to recommend one here and now, since I don't know the
details. Do find a book or look on the Web for "serialization" of C++
objects. They can probably explain it better than I can.

V
Jul 23 '05 #9

P: n/a

"Victor Bazarov" <v.********@comAcast.net> schrieb im Newsbeitrag
news:Iu*******************@newsread1.mlpsca01.us.t o.verio.net...
Jan-Henrik Grobe wrote:
[..]
Token is another with assignable and unassignable objects.
If that's so, then Token may not be assignable, and that's your problem.
I must say, that
I havent written the Token-class and the Y-class by myself and they
cannot be changed.


That's too bad.
My job is only to "copy out" the Y-object out of the X-object
and send it over the net to "paste it in" the X-object that is running on
the client PC.


I am not blaming you or trying to make you do what you don't want to.
I dont know...maybe it is possible to get the pointer from
the y-object and create a new y-object in the main application and assign
the value behind the pointer to that new object

In some cases you can get away with some binary content, especially if you
do not cross platform borders, in other instances you need to convert your
internal representations into some kind of text stream, formed on one end
and interpreted at the other end. I don't know which you'll pick, nor do
I claim the ability to recommend one here and now, since I don't know the
details. Do find a book or look on the Web for "serialization" of C++
objects. They can probably explain it better than I can.

V


Now I realize somehow in what trash I am :-) Yesterday evening I thought
that programming this all would take me about 15 minutes and everything will
run fine.

I am working on a kind of interaction manager for a CAVE virtual
environment....interaction is performed on the server PC which is pushing
the information through a network to the clients that render my Cavewalls. I
have a class X object running on all computers...the Y class objects
contains the information, how the geometry is "modified" (complexer
geometric function). On the server (where the interaction is performed), the
y-object will be continuiously modifizied depending on the actions the user
does...but to render all this, I have to send it to the clients.

So much to my work

I have never really coped a lot with networks and object referencing,
copying, etc....but somehow it cannot be so hard to instance a new object
with the data from an existing object, irrelevant if it is pod or not.
It seems that what you're solving here is a *serialization* problem. You
need to send information over the wires, which should represent the 'Y'
object in such way that it can be recreated. Without knowing the problem
domain in detail (not that I'm asking you to fill me in) it is difficult
to give you more specific advice than the following. Try to imagine what
information you need to be able to recreate a 'Y' on the other end of your
transmission and stick it into your other 'X'. Perhaps you need to make
up another type, like 'Y_proto', which will be created by your 'X', then
transmitted somehow and then used by the other 'X' to generate the proper
'Y' object inside it. You do have control over 'X', don't you?


yes, I can add functions to X if I want....I already added the getObjectY
function. But changes in the geometric parts I cannot do.

Probably I should leave it away for the weekend :-)

Greetings
Jan
Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.