2

For some reason, I'm not able to initialize a set of pointers to an abstract data type like so:

gkAnimation* run = NULL, walk = NULL, idle = NULL;

I'm getting an error saying:

jni/STEP3D_GK_Wrapper_JNI.cpp:283:34: error: cannot allocate an object of abstract type 'gkAnimation'

I haven't had this issue happen before, and I don't think the class itself is doing anything special for this error to happen or that it would matter. I can post more code if it helps, but I'm pretty stumped here. Any ideas?

Justin Meiners
  • 10,754
  • 6
  • 50
  • 92
mpellegr
  • 3,072
  • 3
  • 22
  • 36

1 Answers1

8

The problem is that this syntax:

gkAnimation* run = NULL, walk = NULL, idle = NULL;

Does not mean:

gkAnimation* run = NULL;
gkAnimation* walk = NULL;
gkAnimation* idle = NULL;

It means:

gkAnimation* run = NULL;
gkAnimation walk = NULL; /* invalid */
gkAnimation idle = NULL; /* invalid */

You need to explicitly define each item in the list as a pointer:

gkAnimation *run = NULL, *walk = NULL, *idle = NULL;

This is why many prefer the syntax style of placing the pointer next to the variable rather than next to the type.

Justin Meiners
  • 10,754
  • 6
  • 50
  • 92