• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Stupid C++ Question

schizoid

Banned
I'm retarded (or, rather, I'm a grad student who hasn't touched C++ in fer days) and I can't remember how to do the following:

I have this threaded zorch that has a couple of shared queues, along with send and recieve threads. The send threads pick things off the queue and send them etc. My problem is that the push and pop functions to access the queue (it's standard queue.h stuff, I didn't write them) take a char* as a parameter. I want to be able to push and pop a class object. Now, if I could just cast the thing to a char* that'd work, because (and i know this is crappy tecnique, but whatever) all the systems this thingee is running on have the same OS/compiler/etc so if I sent a class/struct over as plain text, I can just cast it back and everything is peachy.

But you can't just cast a random-ass class to a char*...but i know there has got to be a way to make it plain text so I can push it to the queue etc.

Any ideas (and don't shoot me if it's something super-easy)

Thanks.
 
Originally posted by: schizoid
Someone want to explain to me why this is the wrong forum but this isn't?

now let's not point fingers here.

The reason is because some members really don't care one way or another. But both threads should technically be in another forum. Software I think.


BTW: What is a zorch?
 
Originally posted by: schizoid
I'm retarded (or, rather, I'm a grad student who hasn't touched C++ in fer days) and I can't remember how to do the following:

I have this threaded zorch that has a couple of shared queues, along with send and recieve threads. The send threads pick things off the queue and send them etc. My problem is that the push and pop functions to access the queue (it's standard queue.h stuff, I didn't write them) take a char* as a parameter. I want to be able to push and pop a class object. Now, if I could just cast the thing to a char* that'd work, because (and i know this is crappy tecnique, but whatever) all the systems this thingee is running on have the same OS/compiler/etc so if I sent a class/struct over as plain text, I can just cast it back and everything is peachy.

But you can't just cast a random-ass class to a char*...but i know there has got to be a way to make it plain text so I can push it to the queue etc.

Any ideas (and don't shoot me if it's something super-easy)

Thanks.

You need to either template the queue or modify the code to use your class type. No way around that if you want the queue to be handling classes and not primitives.
 
Originally posted by: schizoid
I'm retarded (or, rather, I'm a grad student who hasn't touched C++ in fer days) and I can't remember how to do the following:

I have this threaded zorch that has a couple of shared queues, along with send and recieve threads. The send threads pick things off the queue and send them etc. My problem is that the push and pop functions to access the queue (it's standard queue.h stuff, I didn't write them) take a char* as a parameter. I want to be able to push and pop a class object. Now, if I could just cast the thing to a char* that'd work, because (and i know this is crappy tecnique, but whatever) all the systems this thingee is running on have the same OS/compiler/etc so if I sent a class/struct over as plain text, I can just cast it back and everything is peachy.

But you can't just cast a random-ass class to a char*...but i know there has got to be a way to make it plain text so I can push it to the queue etc.

Any ideas (and don't shoot me if it's something super-easy)

Thanks.

You want to use STL.

deque<classtype> que; //declare a double ended queue of type classtype

 
Originally posted by: yoda291
Originally posted by: schizoid
Someone want to explain to me why this is the wrong forum but this isn't?

now let's not point fingers here.

The reason is because some members really don't care one way or another. But both threads should technically be in another forum. Software I think.


BTW: What is a zorch?

That's what Spaceman Spiff's gun does to aliens. I guess he's writing some sort of logic program to queue up enemies in the gun's memory and have it auto-aim/fire.
 
Originally posted by: charrison
Originally posted by: schizoid
I'm retarded (or, rather, I'm a grad student who hasn't touched C++ in fer days) and I can't remember how to do the following:

I have this threaded zorch that has a couple of shared queues, along with send and recieve threads. The send threads pick things off the queue and send them etc. My problem is that the push and pop functions to access the queue (it's standard queue.h stuff, I didn't write them) take a char* as a parameter. I want to be able to push and pop a class object. Now, if I could just cast the thing to a char* that'd work, because (and i know this is crappy tecnique, but whatever) all the systems this thingee is running on have the same OS/compiler/etc so if I sent a class/struct over as plain text, I can just cast it back and everything is peachy.

But you can't just cast a random-ass class to a char*...but i know there has got to be a way to make it plain text so I can push it to the queue etc.

Any ideas (and don't shoot me if it's something super-easy)

Thanks.

You want to use STL.

deque<classtype> que; //declare a double ended queue of type classtype


Oh yeah...STL. 2 semesters of "here's how you do it yourself" are still fresh in my mind, this semester they're showing us the easy way. 😀
 
Originally posted by: KingNothing
Originally posted by: charrison
Originally posted by: schizoid
I'm retarded (or, rather, I'm a grad student who hasn't touched C++ in fer days) and I can't remember how to do the following:

I have this threaded zorch that has a couple of shared queues, along with send and recieve threads. The send threads pick things off the queue and send them etc. My problem is that the push and pop functions to access the queue (it's standard queue.h stuff, I didn't write them) take a char* as a parameter. I want to be able to push and pop a class object. Now, if I could just cast the thing to a char* that'd work, because (and i know this is crappy tecnique, but whatever) all the systems this thingee is running on have the same OS/compiler/etc so if I sent a class/struct over as plain text, I can just cast it back and everything is peachy.

But you can't just cast a random-ass class to a char*...but i know there has got to be a way to make it plain text so I can push it to the queue etc.

Any ideas (and don't shoot me if it's something super-easy)

Thanks.

You want to use STL.

deque<classtype> que; //declare a double ended queue of type classtype


Oh yeah...STL. 2 semesters of "here's how you do it yourself" are still fresh in my mind, this semester they're showing us the easy way. 😀

It is good to know how to do it yourself, since STL is not perfect 🙂 It is damn good, but definatly not perfect.
 
Originally posted by: yoda291
Originally posted by: schizoid
Someone want to explain to me why this is the wrong forum but this isn't?

now let's not point fingers here.

The reason is because some members really don't care one way or another. But both threads should technically be in another forum. Software I think.


BTW: What is a zorch?

A zorch is like a doohickus, or a veeblefetzer, or possibly a thingamabob.

 
Originally posted by: charrison
Originally posted by: KingNothing
Originally posted by: charrison
Originally posted by: schizoid
I'm retarded (or, rather, I'm a grad student who hasn't touched C++ in fer days) and I can't remember how to do the following:

I have this threaded zorch that has a couple of shared queues, along with send and recieve threads. The send threads pick things off the queue and send them etc. My problem is that the push and pop functions to access the queue (it's standard queue.h stuff, I didn't write them) take a char* as a parameter. I want to be able to push and pop a class object. Now, if I could just cast the thing to a char* that'd work, because (and i know this is crappy tecnique, but whatever) all the systems this thingee is running on have the same OS/compiler/etc so if I sent a class/struct over as plain text, I can just cast it back and everything is peachy.

But you can't just cast a random-ass class to a char*...but i know there has got to be a way to make it plain text so I can push it to the queue etc.

Any ideas (and don't shoot me if it's something super-easy)

Thanks.

You want to use STL.

deque<classtype> que; //declare a double ended queue of type classtype


Oh yeah...STL. 2 semesters of "here's how you do it yourself" are still fresh in my mind, this semester they're showing us the easy way. 😀

It is good to know how to do it yourself, since STL is not perfect 🙂 It is damn good, but definatly not perfect.

I'll take slightly imperfect in return for having a templated double-ended queue waiting for me when I fire up vim. And don't get me started on writing a templated queue in C...that was wretched.
 
Back
Top