Python programmer totally new to c++. Rewriting https://github.com/karpathy/scriptsbots as my first project. You may be able to follow this question without having to read the actual code.
The author uses a pattern that I can't understand.
- He defines a
GLView
class (here) - Then rather than using the class directly, he creates a pointer to an instance of the class like so
GLView* GLVIEW = new GLView(0);
. Also worth noting thatGLView.h
forward declaresGLVIEW
(here). - And rather than making use of the class methods directly, he defines functions that call the methods via the pointer to the instance. For example:
void gl_changeSize(int w, int h) {GLVIEW->changeSize(w,h)}
.
I suppose there must be some purpose for all this that I'm not seeing yet. So what's this pattern for? Is it common? Does it have a name?
If helpful, here's what's going on in my head: why not
- Make an instance of
GLView
like this:glView = GLView();
- Call its methods like this:
glView.gl_changeSize()
Aucun commentaire:
Enregistrer un commentaire