Go Down

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


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.

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:
anywhere in the code. That would be equivalent to the incorrect code I pointed out.


You do NOT directly invoke the constructor. Ever.

unless you use placement new


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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131