Pages: 1 [2]   Go Down
Author Topic: Including Other Files  (Read 938 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Cat cat1;
the constructor is called to create cat1. You do NOT directly invoke the constructor. Ever.

Even using pointers,
Code:
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:
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.
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You do NOT directly invoke the constructor. Ever.
unless you use placement new
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 [2]   Go Up
Jump to: