Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

I want to create c++ style's interrupt method, But doesn't work

Posted on 2003-02-28
5
Medium Priority
?
276 Views
Last Modified: 2010-04-01
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.
0
Comment
Question by:cplus66
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 8044466
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
 

Author Comment

by:cplus66
ID: 8044580
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
 
LVL 86

Expert Comment

by:jkr
ID: 8044638
Nope (except from hacky assembler solutions), you cannot bypass 'static'.
0
 

Author Comment

by:cplus66
ID: 8044765
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
 

Author Comment

by:cplus66
ID: 8044770
It is excellent. Thanks.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question