user33435: I have two classes in my sketch that are independent of each other (a serial output and an LCD display) A simplified structure of my code is as follows:
class A
{
  public:
   int x;
   void afoo()
   {
     x=1;
   }
   void afoo2
   {
     x=ClassB.bfoo+1;
   }
};

A ClassA;

class B
{
  public:
    int y;
    void bfoo()
    {
      y=ClassA.afoo+2;
    }
};
B ClassB;

However, if I don't comment out  class afoo2 I get the following error:

exit status 1
'ClassB' was not declared in this scope

I'm guessing that this is because I haven't yet created B ClassB while class is being defined. Is there a way I can do what I'm intending here?

user31105: What you are trying to do is call class A from B and vice versa. 
What you could try, is remove one of the functions out of the class, possibly to a third class, so class A and B depend on a class C and not on each other.
However, if they are really depend, you can split up the files in header/implementation files.
Instead of using two classes directly, pass them as a parameter (reference).
Somewhat like this (not tested)
File A.h:
class A
{
  public:
   int x;
   void afoo();
   void afoo2(B& b);
};

File A.cpp:
#include "A.h" 
#include "B.h" 

void A::afoo()
{
  x=1;
}

void A::afoo2(B& b)
{
  x=b.bfoo+1;
}

file B.h:
class B
{
  public:
    int y;
    void bfoo(A& a);
}

file B.cpp:
#include "A.h" 
#include "B.h" 

B::void bfoo(A& a)
{
  y=a.afoo+2;
}

And your ino file you declare A and B.
#include "A.h"
#include "B.h"

A ClassA;
B ClassB;

ClassA.afoo(ClassB);
ClassB.bfoo(ClassA);


user4143: You can't see non-static member variables in a class like that.  The closest is to make it static, which means you get one and only one copy of the variable across all instances of your class:
class ClassB;
class ClassA {
    public:
        int x;
        void foo();

};
class ClassB {
    public:
        static int bfoo;
};

void ClassA::foo() {
    x = ClassB::bfoo + 1;
}

However I suspect that isn't what you want. I suspect you actually want to see the bfoo value stored in class instance B - so you need to tell you classA instance A what and where B is. To do that you will have to pass it when constructing or during some other setup phase.  If you want A to know B and B to know A you can't easily do it during construction, so you will have to do it at a later stage:
class ClassB;

class ClassA {
    public:
        ClassB *B;
        int fooa;
        void begin(ClassB *b) {
            B = b;
        }
        void foo();
};
class ClassB {
    public:
        ClassA *A;
        int foob;
        void begin(ClassA *a) {
            A = a;
        }
        void foo();
};

void ClassA::foo() {
    fooa = B->foob + 1;
}

void ClassB::foo() {
    foob = A->fooa + 1;
}

ClassA A;
ClassB B;

void setup() {
    A.begin(&B);
    B.begin(&A);
}

void loop() {

}


33435: <p>I have two classes in my sketch that are independent of each other (a serial output and an LCD display) A simplified structure of my code is as follows:</p>
<pre><code>class A
{
  public:
   int x;
   void afoo()
   {
     x=1;
   }
   void afoo2
   {
     x=ClassB.bfoo+1;
   }
};

A ClassA;

class B
{
  public:
    int y;
    void bfoo()
    {
      y=ClassA.afoo+2;
    }
};
B ClassB;
</code></pre>
<p>However, if I don't comment out  <code>class afoo2</code> I get the following error:</p>
<blockquote>
<p>exit status 1</p>
<p><code>'ClassB' was not declared in this scope</code></p>
</blockquote>
<p>I'm guessing that this is because I haven't yet created <code>B ClassB</code> while class is being defined. Is there a way I can do what I'm intending here?</p>
 31105: <p>What you are trying to do is call class A from B and vice versa. </p>

<p>What you could try, is remove one of the functions out of the class, possibly to a third class, so class A and B depend on a class C and not on each other.</p>

<p>However, if they are really depend, you can split up the files in header/implementation files.</p>

<p>Instead of using two classes directly, pass them as a parameter (reference).</p>

<p>Somewhat like this (not tested)</p>

<p>File A.h:</p>

<pre><code>class A
{
  public:
   int x;
   void afoo();
   void afoo2(B&amp; b);
};
</code></pre>

<p>File A.cpp:</p>

<pre><code>#include "A.h" 
#include "B.h" 

void A::afoo()
{
  x=1;
}

void A::afoo2(B&amp; b)
{
  x=b.bfoo+1;
}
</code></pre>

<p>file B.h:</p>

<pre><code>class B
{
  public:
    int y;
    void bfoo(A&amp; a);
}
</code></pre>

<p>file B.cpp:</p>

<pre><code>#include "A.h" 
#include "B.h" 

B::void bfoo(A&amp; a)
{
  y=a.afoo+2;
}
</code></pre>

<p>And your ino file you declare A and B.</p>

<pre><code>#include "A.h"
#include "B.h"

A ClassA;
B ClassB;

ClassA.afoo(ClassB);
ClassB.bfoo(ClassA);
</code></pre>
 4143: <p>You can't see non-static member variables in a class like that.  The closest is to make it <code>static</code>, which means you get one and only one copy of the variable across all instances of your class:</p>

<pre><code>class ClassB;
class ClassA {
    public:
        int x;
        void foo();

};
class ClassB {
    public:
        static int bfoo;
};

void ClassA::foo() {
    x = ClassB::bfoo + 1;
}
</code></pre>

<p>However I suspect that isn't what you want. I suspect you actually want to see the <code>bfoo</code> value stored in class instance <code>B</code> - so you need to tell you <code>classA</code> instance <code>A</code> what and where <code>B</code> is. To do that you will have to pass it when constructing or during some other setup phase.  If you want A to know B and B to know A you can't easily do it during construction, so you will have to do it at a later stage:</p>

<pre><code>class ClassB;

class ClassA {
    public:
        ClassB *B;
        int fooa;
        void begin(ClassB *b) {
            B = b;
        }
        void foo();
};
class ClassB {
    public:
        ClassA *A;
        int foob;
        void begin(ClassA *a) {
            A = a;
        }
        void foo();
};

void ClassA::foo() {
    fooa = B-&gt;foob + 1;
}

void ClassB::foo() {
    foob = A-&gt;fooa + 1;
}

ClassA A;
ClassB B;

void setup() {
    A.begin(&amp;B);
    B.begin(&amp;A);
}

void loop() {

}
</code></pre>
