?
Solved

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

Posted on 2003-02-28
5
Medium Priority
?
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

800 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