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.
cplus66Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Make the interrupt handler a static member of your class and it will work. Nonstatic members receive a hidden 'this' pointer as the 1st argument, thus the error.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cplus66Author Commented:
Thanks. Is any way that I can bypass using static since I have so many subclasses derived from this class? (Yes, you remind me that I did static last time).
0
jkrCommented:
Nope (except from hacky assembler solutions), you cannot bypass 'static'.
0
cplus66Author Commented:
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));
0
cplus66Author Commented:
It is excellent. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.