In the following I define an object "foo" by just writing "Foo foo();" in the "root of the file" (what I mean is: not inside a function). Is there a nice word/term for this kind of initialization, as opposed to initializing an object within a function?
It seems like the constructor is just never called. Is it ever called then? Or should I do something more to initialize the "foo" object?
As the code demonstrates, the constructor IS called when initializing objects of class Foo inside a function.
int count = 0;
class Foo
{
public:
Foo ();
};
Foo::Foo() {
count ++;
}
Foo foo(); // initialize one
void setup() {
Serial.begin(9600);
while(!Serial);
}
// the loop routine runs over and over again forever:
void loop() {
Serial.println(count);
Foo();
delay(1000);
}
Please correct me if I am using the terms initialization/declaration/construction wrong.
Sincerely