user42: I wanted to move some of my code out into a second tab in the Arduino IDE, to keep things better organised. At first, I only tried moving a function, and it seemed to work fine. I could call the function from the setup() function in my main tab, and there were no problems compiling or uploading.
However, I tried putting a whole class into the second tab, and suddenly it didn't work any more. For example:
Tab 1:

TestClass obj;

void setup()
{
    obj.init();
}

void loop()
{
    //...
}

Tab 2:
class TestClass
{
public:
    void init()
    {
        //...
    }
};

When I tried to compile this, it gave me the following errors:
tab1:1: error: 'TestClass' does not name a type
tab1.ino: In function 'void setup()':
tab1:5: error: 'obj' was not declared in this scope

Why does it recognise a function in another tab, but not a class? Is there a way to make it work in the Arduino IDE, or do I need to use an alternative like Eclipse?

user10: The way the Arduino IDE works is that it compiles your code (the code you write in the IDE) as the "main" code. Then it pulls code from all of the libraries you have imported and compiles that along with the main code. To do what you are suggesting would require you to create a library for Arduino.
Here is some more information on Arduino libraries:
http://arduino.cc/en/Guide/Libraries
And here is some on how to create a library:
http://arduino.cc/en/Hacking/LibraryTutorial //this one is the easiest to understand imo
http://playground.arduino.cc/Code/Library 
http://www.divilabs.com/2013/03/write-your-own-arduino-library.html# 
Here is an example library I wrote https://github.com/jamolnng/Arduino/tree/master/libraries/ShiftRegister as you can see there is no problem with calling Arduino functions from the .cpp file (I know, I've tested the library)

user65: It is not possible to declare and use classes declared in one .pde file in another .pde file from within the Arduino IDE.
One workaround is to make the second file into a C++ source file (.cpp) and then add a #include "<filename>" directive in the beginning of the first file.

This code compiles correctly:
Tab 1:
#include "test.cpp"

TestClass obj;

void setup()
{
    obj.init();
}

void loop()
{
    //...
}

test.cpp :
class TestClass
{
public:
    void init()
    {
        //...
    }
};


42: <p>I wanted to move some of my code out into a second tab in the Arduino IDE, to keep things better organised. At first, I only tried moving a function, and it seemed to work fine. I could call the function from the <code>setup()</code> function in my main tab, and there were no problems compiling or uploading.</p>

<p>However, I tried putting a whole class into the second tab, and suddenly it didn't work any more. For example:</p>

<p><strong>Tab 1:</strong>
</p>

<pre><code>TestClass obj;

void setup()
{
    obj.init();
}

void loop()
{
    //...
}
</code></pre>

<p><strong>Tab 2:</strong></p>

<pre><code>class TestClass
{
public:
    void init()
    {
        //...
    }
};
</code></pre>

<p>When I tried to compile this, it gave me the following errors:</p>

<pre><code>tab1:1: error: 'TestClass' does not name a type
tab1.ino: In function 'void setup()':
tab1:5: error: 'obj' was not declared in this scope
</code></pre>

<p>Why does it recognise a function in another tab, but not a class? Is there a way to make it work in the Arduino IDE, or do I need to use an alternative like Eclipse?</p>
 10: <p>The way the Arduino IDE works is that it compiles your code (the code you write in the IDE) as the &quot;main&quot; code. Then it pulls code from all of the libraries you have imported and compiles that along with the main code. To do what you are suggesting would require you to create a library for Arduino.</p>
<h3>Here is some more information on Arduino libraries:</h3>
<p><a href="http://arduino.cc/en/Guide/Libraries" rel="nofollow noreferrer">http://arduino.cc/en/Guide/Libraries</a></p>
<h3>And here is some on how to create a library:</h3>
<p><a href="http://arduino.cc/en/Hacking/LibraryTutorial" rel="nofollow noreferrer">http://arduino.cc/en/Hacking/LibraryTutorial</a> //this one is the easiest to understand imo<br />
<a href="http://playground.arduino.cc/Code/Library" rel="nofollow noreferrer">http://playground.arduino.cc/Code/Library</a> <br />
<a href="http://www.divilabs.com/2013/03/write-your-own-arduino-library.html#" rel="nofollow noreferrer">http://www.divilabs.com/2013/03/write-your-own-arduino-library.html#</a> <br /></p>
<p>Here is an example library I wrote <a href="https://github.com/jamolnng/Arduino/tree/master/libraries/ShiftRegister" rel="nofollow noreferrer">https://github.com/jamolnng/Arduino/tree/master/libraries/ShiftRegister</a> as you can see there is no problem with calling Arduino functions from the .cpp file (I know, I've tested the library)</p>
 65: <p>It is not possible to declare and use classes declared in one <code>.pde</code> file in another <code>.pde</code> file from within the Arduino IDE.</p>

<p>One workaround is to make the second file into a C++ source file (<code>.cpp</code>) and then add a <code>#include "&lt;filename&gt;"</code> directive in the beginning of the first file.</p>

<hr>

<p>This code compiles correctly:</p>

<p>Tab 1:</p>

<pre><code>#include "test.cpp"

TestClass obj;

void setup()
{
    obj.init();
}

void loop()
{
    //...
}
</code></pre>

<p>test.cpp :</p>

<pre><code>class TestClass
{
public:
    void init()
    {
        //...
    }
};
</code></pre>
