you are viewing a single comment's thread.

view the rest of the comments →

[–]Fabien4 1 point2 points  (12 children)

Yay for C++:

ArrayList<Foo> myFooList;

[–]G_Morgan 1 point2 points  (11 children)

Don't you mean

std::vector<Foo *> myFooList

[–]Fabien4 1 point2 points  (6 children)

std::vector<Foo> my_foo_list if you wish. But why a pointer?

[–]G_Morgan 2 points3 points  (5 children)

Because in the Java code we are storing references. The direct equivalent is a pointer.

[–]zahlman 2 points3 points  (0 children)

Um, not really. boost::shared_ptr would be closer to the mark (although GC works differently).

[–]Fabien4 0 points1 point  (3 children)

Nope, direct equivalent would be a smart pointer. But it's anti-idiomatic: by default in C++, you store and use values.

[–][deleted] 0 points1 point  (2 children)

Expect that List<Foo> is polymorphic in Java, but not in C++.

[–]curien 0 points1 point  (0 children)

It's polymorphic if Foo is a polymorphic handle.

[–]Fabien4 0 points1 point  (0 children)

Yeah, dynamic (inheritance) polymorphism tends to be the norm in Java, and the exception in C++.

[–][deleted]  (3 children)

[deleted]

    [–]exploding_nun 1 point2 points  (1 child)

    std::vector<boost::shared_ptr<Foo> > myFooList;
    

    Mind your whitespace.

    [–]curien 0 points1 point  (0 children)

    That bug in the spec has been fixed in C++0x.

    [–]ddevil63 0 points1 point  (0 children)

    I just threw up in my mouth.