Go Down

Topic: Including Other Files (Read 1 time) previous topic - next topic

PaulS

Quote
Can you give me an example of how to properly invoke a constructor from another file?

You already have that. When you declare an instance, like:
Code: [Select]
Cat cat1;
the constructor is called to create cat1. You do NOT directly invoke the constructor. Ever.

Even using pointers,
Code: [Select]
Cat *pCat = new Cat();
is not directly invoking the constructor. The constructor IS invoked, but indirectly, just as in the object case.

Quote
I do not have a problem with any of the other classes I have and I handled them the same way so i dont really see what the problem is.

That is not true. You are NOT handling them the same way:
Code: [Select]
static Ghost ghost1;

There is no attempt to call to the constructor, like so:
ghost1.Ghost();
anywhere in the code. That would be equivalent to the incorrect code I pointed out.

WizenedEE

You do NOT directly invoke the constructor. Ever.

unless you use placement new

PaulS

Quote
unless you use placement new

That's still using new to indirectly invoke the constructor, as I read it. Not that placement new is supported on the Arduino.

Go Up