cplus66
asked on
I want to create c++ style's interrupt method, But doesn't work
Hi Guys:
I have sample class:
HEADER:
#ifndef __TEST__
#define __TEST__
#endif
#include <dos.h>
class Test {
inline void interrupt handler(void) { /* do something */}
void test();
};
CPP:
#include "Test.h"
void Test::test() {
setvect(0, handler);
}
It won't compile:
Member function must be called or its address taken
Type mismatch in parameter '__handler' in call to 'setvect(int, void (interrupt *)(...))'
I got compiled successfully before but forgot exactly how and only remember using inline. If I change it like this:
HEADER:
#ifndef __TEST__
#define __TEST__
#endif
#include <dos.h>
class Test {
void test();
};
CPP:
#include "Test.h"
void interrupt handler(void) { /* do something */}
void Test::test() {
setvect(0, handler);
}
It compiles, the only difference is that interrupt function is not the member of class Test, and actual type doesn't change. Why I got this kind of errors? I tried to find out how I did before but totally forgot? Thank you so much for help.
Anyway, what type does setvect function expect. It should expect "void (interrupt *)(...)" type but both ways do the same thing. I don't understand.
I have sample class:
HEADER:
#ifndef __TEST__
#define __TEST__
#endif
#include <dos.h>
class Test {
inline void interrupt handler(void) { /* do something */}
void test();
};
CPP:
#include "Test.h"
void Test::test() {
setvect(0, handler);
}
It won't compile:
Member function must be called or its address taken
Type mismatch in parameter '__handler' in call to 'setvect(int, void (interrupt *)(...))'
I got compiled successfully before but forgot exactly how and only remember using inline. If I change it like this:
HEADER:
#ifndef __TEST__
#define __TEST__
#endif
#include <dos.h>
class Test {
void test();
};
CPP:
#include "Test.h"
void interrupt handler(void) { /* do something */}
void Test::test() {
setvect(0, handler);
}
It compiles, the only difference is that interrupt function is not the member of class Test, and actual type doesn't change. Why I got this kind of errors? I tried to find out how I did before but totally forgot? Thank you so much for help.
Anyway, what type does setvect function expect. It should expect "void (interrupt *)(...)" type but both ways do the same thing. I don't understand.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nope (except from hacky assembler solutions), you cannot bypass 'static'.
ASKER
Thanks. I am accepting your first comment as my anser. Would you please explain "Nonstatic members receive a hidden 'this' pointer as the 1st argument". I am kind of confusion. What you mean 1st argument:
It does like: setvect(0, void interrupt this.handler(void));
OR like: setvect(0, void interrrupt handler(this, void));
It does like: setvect(0, void interrupt this.handler(void));
OR like: setvect(0, void interrrupt handler(this, void));
ASKER
It is excellent. Thanks.
ASKER