Main Menu

C++ Question

Started by john k2ox, October 09, 2013, 08:52:59 AM

john k2ox

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

Felix

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();
}


?

john k2ox


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