| delorie.com/archives/browse.cgi | search |
| From: | Martin Ambuhl <mambuhl AT earthlink DOT net> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: C++ problem |
| Date: | Thu, 01 Oct 1998 04:32:18 -0400 |
| Organization: | Nocturnal Aviation |
| Lines: | 65 |
| Message-ID: | <36133E12.794625F9@earthlink.net> |
| References: | <6udqfn$sdk$1 AT inf6serv DOT rug DOT ac DOT be> <360A8B31 DOT 53CF31E9 AT earthlink DOT net> <36101229 DOT C4659B15 AT unb DOT ca> |
| NNTP-Posting-Host: | 1cust223.tnt9.nyc3.da.uu.net |
| Mime-Version: | 1.0 |
| X-Posted-Path-Was: | not-for-mail |
| X-ELN-Date: | Thu Oct 1 01:29:35 1998 |
| X-Mailer: | Mozilla 4.06 [en] (Win95; U) |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Endlisnis wrote:
>
> Martin Ambuhl wrote:
>
> > void SetMode(int mode) {
> > if (mode == 0)
> > PrintPtr = &PrintMode0;
> > if (mode == 1)
> > PrintPtr = &PrintMode1;
> > }
>
> This is wrong. It would take the address of the variable containing the
> address of the function.--
Ok. I invite "Endlisnis" to point me to the "variable containing the
address of the function". Get a clue before posting "corrections."
The code from which this was extracted, in which PrintMode[01] are
member functions and not variables:
#include <stdio.h>
class Test
{
int testint;
void (Test::*PrintPtr) ();
public:
Test(int in_testint) {
testint = in_testint;
}
void SetMode(int mode) {
if (mode == 0)
PrintPtr = &PrintMode0;
if (mode == 1)
PrintPtr = &PrintMode1;
}
void PrintMode0() {
printf("mode 0: %d\n", testint);
}
void PrintMode1() {
printf("mode 1: %d\n", testint);
}
void Print() {
(this->*PrintPtr)();
}
};
int main()
{
Test test1(10);
test1.SetMode(0);
test1.Print(); // This should print 10
return 0;
}
> (\/) Endlisnis (\/)
> s257m AT unb DOT ca
> Endlisnis AT GeoCities DOT com
> Endlisnis AT BrunNet DOT Net
--
Martin Ambuhl (mambuhl AT earthlink DOT net)
Note: mambuhl AT tiac DOT net will soon be inactive
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |