I need to convert a .c file into .cpp file and I came across this declaration:
typedef void handler_t(int);
handler_t *Signal(int signum, handler_t *handler);
I included those two lines of code in the header file, and I add the actual function declaration function in the .cpp file.
handler_t *Signal(int signum, handler_t *handler){ ...... }
When I do this I get the error: "handler_t does not name a type".I have never worked before with typdef in C or C++, so can someone explain to me why I am getting an error?
My classes as requested:
#ifndef A_H
#define A_H
class A
{
public:
A();
virtual ~A();
typedef void handler_t(int);
handler_t* Signal(int signum, handler_t *handler);
protected:
private:
};
#endif // A_H
/////////////
#include "A.h"
A::A()
{
}
A::~A()
{
}
handler_t* A::Signal(int signum, handler_t *handler) {
...........
}
error:
|694|error: ‘handler_t’ does not name a type|
Try changing it to:
typedef void (*handler_t)(int);
and:
handler_t Signal(int signum, handler_t handler);
For reference check out signal() which does it like this:
#include <signal.h>
typedef void (*sighandler_t)(int);
sighandler_t signal(int signum, sighandler_t handler);
Actually, looking at your new code, I think you have to do this:
A::handler_t* A::Signal(int signum, A::handler_t *handler)
I think your new error "undefined reference to main" is unrelated to the question asked. See this post for some ideas.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With