delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/17/19:15:30

Message-ID: <3790A2D4.204E0595@homemail.com>
From: Matthew Haley <mhaley99 AT homemail DOT com>
X-Mailer: Mozilla 4.08 [en] (Win16; I)
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Need help with class stuff
References: <TnNj3.667$3C2 DOT 65692 AT wagner DOT videotron DOT net>
Lines: 79
Date: Sat, 17 Jul 1999 15:35:48 +0000
NNTP-Posting-Host: 209.181.101.119
X-Trace: news.uswest.net 932251192 209.181.101.119 (Sat, 17 Jul 1999 17:39:52 CDT)
NNTP-Posting-Date: Sat, 17 Jul 1999 17:39:52 CDT
Organization: U S WEST Interprise
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Untested but...

OmniMeta wrote:
> 
> This program call a class function using a pointer to it.
> 
> Can someone please tell me why I get the warning :
> 
> tst.cpp(44) Warning:  converting from `void (Test::*)()' to `void (*)()'
> tst.cpp(45) Warning:  converting from `void (Test::*)()' to `void (*)()'
> 
> Here is the little program :
> 
> #include <stdio.h> // printf
> #include <conio.h> // clrscr getch
> 
> class Test
> {
>   void Print1();
>   void Print2();
> 
>   public:
> 
>   void (*Action)(); // my pointer
> 
>   char select(char key);
> 
> }ClassTest;
> 
> int main()
> {
>   clrscr();
>   printf("Type 1 or 2 : ");  fflush(stdout);
> 
>   do{}
>   while( ClassTest.select(getch()) );
> 
>   ClassTest.Action();
> 
>   printf("\nPress a key to exit");
>   fflush(stdout);
> 
>   getch();
> 
>  return 0;
> }
> 
> char Test::select(char key)
> {
>   switch(key)
>   {                                             // I get the warning at
>    case '1': Action = &Print1; break; // this line
>    case '2': Action = &Print2; break;      // And this line
shouldn't this          ^^^^^^^ be
     case '1': Action = Print1; break;
     case '2': Action = Print2; break;

>     default : return 1;
>   }
>   return 0;
> }
> 
> void Test::Print1()
> {
>  printf("\n\nHello !!!\nThis is what Print1 do.\n");
> }
> 
> void Test::Print2()
> {
>  printf("\n\nHello !!!\nThis is what Print2 do.\n");
> }

-- 

===================================
Matthew Haley
mhaley99 AT homemail DOT com
http://www.users.uswest.net/~mrh99
===================================

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019