CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Join Date
    Jul 2013
    Posts
    576

    Re: What is the equivalence to List<Object> in Java for C++?

    Quote Originally Posted by Arjay View Post
    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.

  2. #17
    Join Date
    Jul 2013
    Posts
    576

    Re: What is the equivalence to List<Object> in Java for C++?

    Quote Originally Posted by zerver View Post
    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.

  3. #18
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: What is the equivalence to List<Object> in Java for C++?

    Quote Originally Posted by razzle View Post
    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?

  4. #19
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: What is the equivalence to List<Object> in Java for C++?

    Quote Originally Posted by lucky6969b View Post
    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

  5. #20
    Join Date
    Oct 2008
    Posts
    1,456

    Re: What is the equivalence to List<Object> in Java for C++?

    Quote Originally Posted by razzle View Post
    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.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured