Create A Class

Hello, is there a way to create a class in the same file as the main program without having to FIRST create a library??

Thanks

Yep.

The declaration looks like this:

class MyClass
{
protected:
    byte m_value;
public:
    MyClass();
    int myMethod(byte arg);
};

Later, the implementation of each method looks like this:

MyClass::MyClass()
{
    m_value = 0;
}

int MyClass::myMethod(byte arg)
{
    m_value = arg;
    return 5*m_value;
}

You then make instances of them like this:

MyClass myThing();

This syntax is a little different but produces identical code, all in one shot:

class MyClass
{
protected:
    byte m_value;
public:
    MyClass()
    {
        m_value = 0;
    }

    int myMethod(byte arg)
    {
        m_value = arg;
        return 5*m_value;
    }
} myThing;