-
December 27th, 2013, 06:04 PM
#16
Re: What is the equivalence to List<Object> in Java for C++?
Originally Posted by Arjay
I only use that tone
So you feel superior indeed.
Interesting. I thought your tone was unintentional.
But then reply to the questions I asked you in my previous post if you dare and I'll cut you to size. It's a promise.
Last edited by razzle; December 27th, 2013 at 06:47 PM.
-
December 27th, 2013, 06:30 PM
#17
Re: What is the equivalence to List<Object> in Java for C++?
Originally Posted by zerver
It does, except that primitive types in java do not derive from Object, and would have to be wrapped.
If void* was God, then Object would be no better than Jesus I guess.
Yes, but this "wrapping" takes place automatically in Java by way of so called boxing/unboxing. It's a coersion polymorphism that's part of the Java language.
So it's trinity that makes void* and Object the same in spirit.
Last edited by razzle; December 27th, 2013 at 07:02 PM.
-
December 28th, 2013, 12:21 AM
#18
Re: What is the equivalence to List<Object> in Java for C++?
Originally Posted by razzle
So you feel superior indeed.
Interesting. I thought your tone was unintentional.
But then reply to the questions I asked you in my previous post if you dare and I'll cut you to size. It's a promise.
Chill out, razzle. From your previous post in the thread, you don't seem to mind taking the superior tone. Or perhaps it was unintentional?
-
December 29th, 2013, 03:32 AM
#19
Re: What is the equivalence to List<Object> in Java for C++?
Originally Posted by lucky6969b
I better off redesign my program. Let me have a good thought about it
Thanks
Jack
First of all, List<Object> is kind of bad design itself, so you're absolutely right about redesign thing. Object is too much abstract interface, and I would expect it be more a trouble than a benefit.
Besides, C++ is not Java, and therefore is not obliged to provide semantically equivalent constructs to what Java developers got used to.
Best regards,
Igor
-
December 30th, 2013, 03:55 AM
#20
Re: What is the equivalence to List<Object> in Java for C++?
Originally Posted by razzle
What would you suggest to better correspond to ArrayList<Object> than std::vector<void*> ?
I don't know Java, but I suppose a List<Object> implies some form of lifetime management of its owned "objects", and I suppose a Java programmer can always use reflection to "cast" an Object to its actual runtime content, doesn't it ?
Conversely, the only thing you can legally do with a void* is essentially to cast it back to its original typed value ( so you cannot even delete a void* ), a vector<void*> is not quite the same thing as a type erased list of objects, it's essentially just a vector of scalar values suitable to represent memory locations, not much more I think.
better alternatives ( modulo usual good design recommendations ) could be vector<shared_ptr<void>> ( which perform true type erasure allowing lifetime management ) or vector<my_smart_ptr<MyBase>>, as OReubens already suggested, or vector<boost::any<MyConcepts>>, vector<boost::variant<...>>, etc ...
BTW, IMO vector<void*> should be a last resort in "low-level" container programming too, because erasing type information inhibits compile-time optimizations, makes dubugging a pain in the ***, etc...
Last edited by superbonzo; December 30th, 2013 at 05:04 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|