home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!concert!rutgers!news.columbia.edu!cunixb.cc.columbia.edu!kps
- From: kps@cunixb.cc.columbia.edu (Karthik P Sheka)
- Newsgroups: comp.lang.c++
- Subject: pointer typecasting question...
- Message-ID: <1992Sep10.210319.4450@news.columbia.edu>
- Date: 10 Sep 92 21:03:19 GMT
- Sender: usenet@news.columbia.edu (The Network News)
- Reply-To: kps@cunixb.cc.columbia.edu (Karthik P Sheka)
- Organization: Columbia University
- Lines: 52
- Nntp-Posting-Host: cunixb.cc.columbia.edu
-
-
- I'm working on a C++ program that is using a C package that is giving
- problems (The package was not meant to be used in C++):
-
- One C call I make, CreateButton, takes as an arguement, a pointer to a
- function that takes one arguement and returns void:
-
- void function(int arguement);
- main()
- {
- CreateButton(function);
- }
-
- When used in a C++ program, I want to send a pointer to an instance of a
- public function. Unfortunately, this does not work:
-
- class func1{
- public:
- function(int arguement);
- };
-
- func1 *instance;
-
- main()
- {
- instance = new func1
- CreateButton(func1->function);
- }
-
-
- What does work is(This is not usable by my program, because it does not
- call an instance of the class):
-
- class func1{
- public:
- function(int arguement);
- };
-
- main()
- {
- void (*called_function)(int) = (void (*)(int))func1::function;
-
- CreateButton(called_function);
- }
-
-
- My question is, "How can I send a pointer to an instance of a function?"
- (I tried
- void (*called_function)(int) = (void (*)(int))instance->function;
- but that doesn't work.)
-
- //Karthik Sheka
-