LowPowerLab Forum

Hardware support => Moteino => Topic started by: john k2ox on October 09, 2013, 08:52:59 AM

Title: C++ Question
Post by: john k2ox on October 09, 2013, 08:52:59 AM
I have two classes and a sketch.

class A
class B

sketch.ino
{
A a;
void func()
  {
   a.doStuff()
  }
}

I would like to move func() from the sketch to class B.  The problem is func() references class A and class B knows nothing about class A.

What's the best way to resolve this?

TIA,
john
Title: Re: C++ Question
Post by: Felix on October 10, 2013, 12:08:38 AM
Well you have to let the function know what A is otherwise you won't be able to use that variable.
Perhaps you can pass a reference into class B?

Ie:

void func(A a_inst)
{
  a_inst.doStuff();
}


?
Title: Re: C++ Question
Post by: john k2ox on October 10, 2013, 09:18:55 AM

I was thinking of multiple inheritance, then nested classes.  I decided its not an is-a, more like a has-a. 

Now I've changed my design I'll leave it a separate class and pass a pointer as you suggest.

I thought I could just move the function from my sketch into a lib without thinking about it in the design phase.  I just might get this OOP stuff yet.

tks,
john