Friday 29 November 2019

c++ - Difference between Object object = new Object() and Object object

If I have a class named Object, what's the difference between creating an instance just like that:



#include 

Object var;

main ()
{

var.test();
}


or



#include 

main ()
{

Object* var = new Object();
var->test();
}


Which is the differente between a global object (which you can use wherever you want) and create a dynamic object in the main.cpp? In theory it should be the same, right? The both method can be used in any file.cpp.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...