Go Down

Topic: Class pointer Array (Read 354 times) previous topic - next topic

MikeGWem

I have some statements that compile perfectly but a variant that results in a compilation error.

The following is just fine
Code: [Select]
MyClass class1;
MyClass class2;
MyClass* classPointers[] = {&class1, &class2};


but this
Code: [Select]
MyClass class1;
MyClass class2;
MyClass* classPointers[] = {NULL, NULL};
classPointers[0] = &class1;

results in "classPointers' does not name a type"

as does
Code: [Select]
MyClass class1;
MyClass class2;
MyClass *classPointers[2];
classPointers[0] = &class1;


Can anyone help me with an explanation?

boolrules

A "show all your code" type of thing?

Whandall

Code: [Select]
class MyClass {};

MyClass class1;
MyClass class2;
MyClass* classPointers[] = {NULL, NULL};

void setup() {
  classPointers[0] = &class1;
}
void loop() {}
Compiles without errors, like expected.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

MikeGWem

Well I suppose that makes sense. It was the nature of the error message that bemused me.
Thanks for the input

Go Up