Re: when to use "new"

From: Rv5 (rmolney_at_adelphia.net)
Date: 11/15/04


Date: Mon, 15 Nov 2004 00:15:59 -0800

I admit that with java I didnt really think of pointers that much, even
though I knew they were being used behind the scenes. I do see the value in
them, but it seems to me that they get used a lot when it isnt necessary.

That said, and back to a spin off of my original question, if I do need just
a pointer to an object and not an object itself, would i use "new" in that
case? For example:
myobject *pointer = new myobject

Just trying to figure out possible scenarios.

ross

> Same advice again, if you don't see the need for pointers don't use them.
> They are tricky to use correctly so avoid them if you can. But I find it
> surprising that you don't see the need if you have been programming Java,
> in Java almost everything is a pointer.
>
> john
>
>



Relevant Pages

  • Re: Getting An Object From A Vector Without Casting
    ... keeping clear when, in a language like Java, I'm working with a pointer ... MyObject myObj = new MyObject; ... as that implies that i is a pointer or a reference. ...
    (comp.lang.java.programmer)
  • Re: The Java no pointer big fat lie!
    ... Does Java have auto variables that construct and destruct by scope? ... Are object references a native memory pointer or an abstracted ... > and reference) ...
    (comp.lang.java.programmer)
  • Re: The Java no pointer big fat lie!
    ... > Whenever I read a Java book and it states that Java has no pointers, ... can't do pointer arithmetic, ie pointer+20 is impossible in Java. ... of the object they reference but to an intermediate which does that. ... A pointer is a memory address in C, no more, no less. ...
    (comp.lang.java.programmer)
  • Re: How java passes object references?
    ... Which everybody knows, it doesn't in Java. ... The reason I think this is a useful clarification is that when you got to the part about how passing by reference might work, it seems you went off track at least partly because you didn't understand the nature of the above. ... is a pointer pointing at the memory block. ... Assignments to local variables, or even to class members, do not allocate memory. ...
    (comp.lang.java.programmer)
  • Re: OT:Re: The End of C++
    ... What I was trying to say, is that if you are to criticise ... I personally very much dislike coding using Java ... code that access memory through an unbounded pointer into an array. ...
    (comp.lang.cpp)