Pointers - declaring new?
I was just wondering something.......
Whne you declare a new pointer, eg:
when do you need to call new? and when is it ok not to?
For example, you might have:
|
someClass *p = new SomeClass(x,y,z);
|
however, i often see in code things like:
|
someClass *p = SomeMethod(a,b,c);
|
whereby new hasn't been called. So when is new needed, and when not?
Thanks
New is called when you want a new object of the class. SomeMethod(a, b, c); probably returns a pointer to someClass.
1 2 3
|
int *p = new int(435);
int number = 534;
int *pointer = &number;
|
there's a simple example. a pointer can point to a value that already exists or you can allocate a new value with new.
Topic archived. No new replies allowed.