user6549: I want to make a timer library. The cpp file I have written is:
#include "avr/interrupt.h"
#include "Arduino.h"

#include "AllTimer.h"

AllTimer::AllTimer()
{}

void AllTimer::dofun(void)
{
    TIFR1 |= _BV(OCF1A);
    TCCR1B = 0X00;
    digitalWrite(13,!digitalRead(13));
}

void AllTimer::setTimer(void)
{
    TCNT1 = 0x0BDC;
    TCCR1A = 0x00;
    TCCR1B = 0x00;
    TCCR1B |= (1<<CS12) && (1<<CS10);
    TIMSK1 |= (1<<TOIE1);
    sei();
}

ISR (TIMER1_OVF_vect)
{
    dofun();
}

And the header file:
#ifndef AllTimer_h
#define AllTimer_h

class AllTimer{
public:
    AllTimer();
    void setTimer(void);

private:
    void dofun(void);
};

#endif

While compiling the file i am getting the following error:
sketch_jan05a.cpp: In function ‘void __vector_13()’:
sketch_jan05a.cpp:34:9: error: ‘dofun’ was not declared in this scope


user42: dofun() is currently declared as a private member function, meaning you can't call it directly. It can only be called internally by an instance of the AllTimer class.
It looks like you probably want to declare it as a public static function instead. To do that, remove the private specifier from the class declaration, and put static before the function declaration. Your header should look something like this:
class AllTimer
{
public:
    AllTimer();
    void setTimer(void);
    static void dofun(void);
};

You will then need to change the ISR to include the class name in the call:
ISR (TIMER1_OVF_vect)
{
    AllTimer::dofun();
}


user6330: Because in the call:
 dofun();

you should put from which class you are calling that function.
In your case:
AllTimer::dofun();

in that case your function must be declared as static method.
EDIT:
Thanks to the comment:
I'm not pretty sure if your code reflects what you want to do. Because you can create your timer after defining the class:
Alltimer mytimer;

and call the method as a normal function (it must be declared as public):
ISR (TIMER1_OVF_vect)
{
    mytimer.dofun();
}

But it is hard to say since I m not sure what you want to do.

6549: <p>I want to make a timer library. The cpp file I have written is:</p>

<pre><code>#include "avr/interrupt.h"
#include "Arduino.h"

#include "AllTimer.h"

AllTimer::AllTimer()
{}

void AllTimer::dofun(void)
{
    TIFR1 |= _BV(OCF1A);
    TCCR1B = 0X00;
    digitalWrite(13,!digitalRead(13));
}

void AllTimer::setTimer(void)
{
    TCNT1 = 0x0BDC;
    TCCR1A = 0x00;
    TCCR1B = 0x00;
    TCCR1B |= (1&lt;&lt;CS12) &amp;&amp; (1&lt;&lt;CS10);
    TIMSK1 |= (1&lt;&lt;TOIE1);
    sei();
}

ISR (TIMER1_OVF_vect)
{
    dofun();
}
</code></pre>

<p>And the header file:</p>

<pre><code>#ifndef AllTimer_h
#define AllTimer_h

class AllTimer{
public:
    AllTimer();
    void setTimer(void);

private:
    void dofun(void);
};

#endif
</code></pre>

<p>While compiling the file i am getting the following error:</p>

<pre><code>sketch_jan05a.cpp: In function ‘void __vector_13()’:
sketch_jan05a.cpp:34:9: error: ‘dofun’ was not declared in this scope
</code></pre>
 42: <p><code>dofun()</code> is currently declared as a private member function, meaning you can't call it directly. It can only be called internally by an instance of the <code>AllTimer</code> class.</p>

<p>It looks like you probably want to declare it as a public static function instead. To do that, remove the <code>private</code> specifier from the class declaration, and put <code>static</code> before the function declaration. Your header should look something like this:</p>

<pre><code>class AllTimer
{
public:
    AllTimer();
    void setTimer(void);
    static void dofun(void);
};
</code></pre>

<p>You will then need to change the ISR to include the class name in the call:</p>

<pre><code>ISR (TIMER1_OVF_vect)
{
    AllTimer::dofun();
}
</code></pre>
 6330: <p>Because in the call:</p>

<pre><code> dofun();
</code></pre>

<p>you should put from which class you are calling that function.
In your case:</p>

<pre><code>AllTimer::dofun();
</code></pre>

<p>in that case your function must be declared as static method.</p>

<p>EDIT:
Thanks to the comment:</p>

<p>I'm not pretty sure if your code reflects what you want to do. Because you can create your timer after defining the class:</p>

<pre><code>Alltimer mytimer;
</code></pre>

<p>and call the method as a normal function (it must be declared as <strong><em>public</em></strong>):</p>

<pre><code>ISR (TIMER1_OVF_vect)
{
    mytimer.dofun();
}
</code></pre>

<p>But it is hard to say since I m not sure what you want to do.</p>
