Skip to main content
added 129 characters in body
Source Link
asheeshr
  • 3.8k
  • 3
  • 26
  • 61

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

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

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()
    {
        //...
    }
};
Source Link
asheeshr
  • 3.8k
  • 3
  • 26
  • 61

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