What is the C++ equivalent of java.lang.Object x = new Foo()?

后端 未结 3 1881
再見小時候
再見小時候 2020-12-10 16:21

What is the C++ equivalent of java.lang.Object x = new Foo()?

3条回答
  •  忘掉有多难
    2020-12-10 16:37

    There is no equivalent because Java allocates objects from a managed heap, C++ allocates them in unmanaged memory. Objects in Java are tracked by the JVM for automatic garbage collection using mark-and-sweep, whereas C++ requires explicit release of all memory.

    The runtime environments are fundamentally different, drawing analogies due to similar looking syntax is a trap.

提交回复
热议问题