Object creation doubt

Hi All,

Can you please let me know what is the difference in object creations like

Say class Test ;


1. Test t1;

2.Test t2*;

3.Test t3*=new Test();


in the above 3 statments what is the difference of creating Objects?

In what type of situations i have to use the above each Statments.


Thanks in advance

Siva
 
Test t1;

creates a new test object using the default constructor.
 
Test t2*;

You are probably thinking of :
 
Test *t2;

Which creates a pointer that points at a Test object. You still will have to initialize the pointer like:
 
t2 = &some_test_object;

the last one:
 
Test *t3 = new test();

creates a pointer to a test object, and dynamically creates the object. If you need to pass arguments to the constructor, you would put them in the parentheses.

Thank you for the clarification. In java we will create every Object Dynamically. Can you please tell me In C++ at what scenarios we will create objects Dynamically and Statically .what is the best way interms of scenarios

Thanks
Siva
Topic archived. No new replies allowed.