| www.delorie.com/archives/browse.cgi | search |
| From: | "OmniMeta" <meta AT abacom DOT com> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Need help with class stuff |
| Lines: | 72 |
| X-Priority: | 3 |
| X-MSMail-Priority: | Normal |
| X-Newsreader: | Microsoft Outlook Express 5.00.2014.211 |
| X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2014.211 |
| Message-ID: | <TnNj3.667$3C2.65692@wagner.videotron.net> |
| Date: | Fri, 16 Jul 1999 17:25:23 -0300 |
| NNTP-Posting-Host: | 207.253.161.51 |
| X-Complaints-To: | abuse AT videotron DOT net |
| X-Trace: | wagner.videotron.net 932160115 207.253.161.51 (Fri, 16 Jul 1999 17:21:55 EDT) |
| NNTP-Posting-Date: | Fri, 16 Jul 1999 17:21:55 EDT |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
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
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");
}
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |