cvs.gedasymbols.org/archives/browse.cgi | search |
From: | "Joe Hagen" <jdhagen AT chorus DOT net> |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Re: calling a pointer to a function |
Date: | Wed, 10 Nov 1999 09:45:41 -0600 |
Organization: | IntraNet Inc: Madison, Wisconsin's ISP |
Lines: | 106 |
Sender: | reguser AT a33-17 DOT madison DOT chorus DOT net |
Message-ID: | <80c40b$268$1@news.chorus.net> |
References: | <382917AA DOT 256A0891 AT home DOT com> |
NNTP-Posting-Host: | a33-17.madison.chorus.net |
X-Priority: | 3 |
X-MSMail-Priority: | Normal |
X-Newsreader: | Microsoft Outlook Express 5.00.2314.1300 |
X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2314.1300 |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
Robin, There are two ways to do this. If you need to do this in regular "C" style, the first example declares PFVI as a pointer to a void function taking an int. In the second example, the PFEXVI typedef is a pointer to a member function of class Ex that returns void and takes an int. EXAMPLE 1: ====================================================== #include <stdio.h> typedef void (*PFVI)(int); void do1(int n) { printf("in do1 n=%d\n",n); } void do2(int n) { printf("in do2 n=%d\n",n); } void callone(PFVI f) { f(1); } int main(void) { callone(do1); return 0; } ==================================================== EXAMPLE 2: ==================================================== #include <iostream> class Ex { typedef void (Ex::*PFEXVI)(int); public: void show(void); private: void do1(int n); void do2(int n); void callone(PFEXVI); }; void Ex::do1(int n) { std::cout << "in do1 n= " << n << std::endl; } void Ex::do2(int n) { std::cout << "in do2 n= " << n << std::endl; } void Ex::callone(PFEXVI f) { (this->*f)(1); } void Ex::show(void) { callone(&Ex::do1); callone(&Ex::do2); } int main(void) { Ex a; a.show(); return 0; } Joe jdhagen AT chorus DOT net Robin Johnson <robbat2 AT home DOT com> wrote in message news:382917AA DOT 256A0891 AT home DOT com... > Hi, > > I used to do something in Pascal, and i was wondering what the C++ > conversion of it was: > {begin pascal code} > Type tProc = Procedure(Num : integer);
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |