Mail Archives: djgpp/1999/08/31/23:09:31
From: | flupke <schawat AT club-internet DOT fr>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Function pointers in C++
|
Date: | Tue, 31 Aug 1999 13:36:51 +0200
|
Organization: | Club-Internet (France)
|
Lines: | 82
|
Message-ID: | <37CBBE53.EECABDD5@club-internet.fr>
|
NNTP-Posting-Host: | toulon-3-5.club-internet.fr
|
Mime-Version: | 1.0
|
X-Trace: | front1.grolier.fr 936100061 10901 195.36.187.5 (31 Aug 1999 11:47:41 GMT)
|
NNTP-Posting-Date: | 31 Aug 1999 11:47:41 GMT
|
X-Mailer: | Mozilla 4.06 [en] (Win98; I)
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Hello.
I don't know if i'm doing a "c++ misunderstanding" or if it's a djgpp
problem, but here is my problem anyway.
When i execute this piece of code:
***********************
#include <iostream.h>
class glou
{
public:
int c;
glou()
{
c = 0;
a = &b;
}
void (*a)();
void b()
{
c++;
}
};
int main()
{
glou blou;
cout << blou.c << endl;
blou.a();
cout << blou.c << endl;
blou.b();
cout << blou.c << endl;
return 0;
}
***********************
I get the output:
0
0
1
Also, i get a warning for the second line of the constructor:
tst.cc(11) Warning: converting from `void (glou::*)()' to `void (*)()'
So i have two questions:
-- how to declare my function pointer so that i get no warning ? If i
try to change "void (*a)()" to: "void (glou::*a)()", i get this error:
tst.cc(28) Error: no match for call to `(void (glou::*)()) ()'
and "void (*glou::a)()" gives me the same warning and output as "void
(*a)()"...
-- how does c++ handle function calling ? why doesn't a() increment
blou::c ?
Thanks for reading this loooong message ;)
Whooops, i just tried to compile the source for the 1000'th time and now
i get:
tst.cc(28) Error: Internal compiler error.
tst.cc(28) Error: Please submit a full bug report to
`bug-g++@prep.ai.mit.edu
(with the "void (glou::*a)()" version of the declaration)
... if i compile it again, it randomly gives me a "compiler" or "no
match for call" error. Please tell me if i'm doing crappy c++ or if it's
really a bug (i use gcc 2.8.0, and rhide under windoze).
- Raw text -