[solved] Classes and multiple instances

Donno if its possible hence me asking the question here in the hope someone knows the answer here! :slight_smile:

Suppose we have a library which contains Class_A and we want to create 2 instances of it, Obj1() and Obj2(), in arduino IDE.

So my understanding at this point is that all the functions in Class_A are basically duplicated into Obj1() and Obj2().

But what if I want to get rid on this duplication? is it possible?

What I mean is that I would want the Obj1() and Obj2() have their independent set of variables as defined in Class_A but share the functions. Is it possible?

On a side node would there be any benefit in terms of memory usage if this was possible?

The functions are not duplicated, just like a normal function called twice is not duplicated.

The programming code of the functions (methods) in a class is created at compile time.
During the execution of your code at runtime it may create multiple instances of that class (objects).
Each object will consume stack space for their own variables but code will not be duplicated.

Beaten to it by westfw

@westfw, @ 6v6gt, thanks for the clarification! you learn something everyday! :wink: