yes not sure in which context that’s mentioned but it’s not necessary, i would say you should almost never use raw pointers in modern c++.
as you say you can do:
Ball ball (0,0 0);
there’s one case in which that gets tricky and that’s when the object is an instance object, that is, when it’s declared on the .h of your ofApp for example. in that case you can’t initialized it there by passing arguments to the contstructor but you can do it in the container class constructor like:
// ofApp.h
ofApp();
...
Ball ball;
// ofApp.cpp
ofApp::ofApp()
:ball(0,0,0){
}
which can be relatively strange for beginners. that among other reasons is why openframeworks tends to not use parameters in constructors for most objects and instead have a setup
method. the other reason is that opengl is sometimes not initialized yet when the constructor is called so doing initializations of objects that require opengl resources in the constructor might be sometimes problematic.
as for the second question, again, i’m not sure what the author is trying to explain, perhaps just memory allocation but i would avoid using pointers like that. instead use a vector of objects like:
// .h
vector<Ball> particles:
//.cpp
particles.push_back(Ball(x,y.ofRandom(10,40));
and forget about allocating memory… from OF 0.9.0 (because we’ll support c++11) you can even do:
particles.emplace_back(x,y,ofRandom(10,40));
which avoids a copy when putting a new element in a vector of objects.
in any case to answer your original question. when you create an object using new, you always need to delete it with delete. if you are used to processing or java, python or similar languages. there an element called the garbage collector takes care of deleting objects that are not used anymore from time to time. c++ doesn’t have garbage collector among other things cause that can slow things down.
in c++ you can use a shared_ptr which works pretty much the same as a raw poitner but auto deletes itself when it’s not being used anymore:
// .h
vector<shared_ptr<Ball>> particles:
//.cpp
particles.push_back(shared_ptr<Ball>(new Ball(x,y.ofRandom(10,40)));
but i would advice against doing this for small objects like particles… and instead use a vector of objects, it’s way simpler and even faster to access later because elements are aligned in memory instead of being scattered as happens when allocating new objects every time you push back a new one in the vector.