| www.delorie.com/archives/browse.cgi | search |
| From: | rob DOT beattie AT net DOT ntl DOT com DOT uk (rob beattie) |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | problem with function pointers |
| Date: | Thu, 21 Oct 1999 20:35:46 GMT |
| Organization: | NTL Internet News Service |
| Lines: | 90 |
| Message-ID: | <380f6eda.12192282@news.net.ntl.com> |
| NNTP-Posting-Host: | delphina-36.cableol.net |
| Mime-Version: | 1.0 |
| X-Trace: | nclient5-gui.server.ntli.net 940538225 15235 194.168.12.36 (21 Oct 1999 20:37:05 GMT) |
| X-Complaints-To: | abuse AT net DOT ntl DOT com |
| NNTP-Posting-Date: | 21 Oct 1999 20:37:05 GMT |
| X-Newsreader: | Forte Agent 1.5/32.452 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
Hi,
I attempted to compile and run the following piece of code using the
DJGPP compiler and have come up against a baffling problem.
#include<iostream.h>
class myclass
{
public:
myclass():normal(1)
{
stat++;
cout<<"Object"<<stat<<"created\n";
}
void shownormal()
{
cout<<"normal="<<normal<<"\n";
}
void showpfunc()
{
cout<<"normal as reprted by pfunc="<<normal<<"\n";
}
void showstatic()
{
cout<<"static="<<stat<<"\n";
}
static void membstatic()
{
cout<<"static="<<stat<<"\n";
}
~myclass()
{
stat--;
cout<<"In the destructor stat="<<stat<<"\n";
}
private:
int normal;
static int stat;
};
int myclass::stat=0;
int main()
{
void (myclass::*pfunc)()=0;
pfunc=myclass::showpfunc;
myclass one;
one.shownormal();
one.membstatic();
one.*pfunc();
myclass two;
two.shownormal();
myclass::membstatic();
two.*pfunc();
myclass three;
three.shownormal();
three.membstatic();
three.*pfunc();
return(0);
}
Sorry about the lack of comments, but I was basically creating three
myclass objects and accessing their static members and functions as
well as practising using pointers to functions.
The compiler reports the warning " in int main.... assuming & on
'myclass::showpfunc()' ". Could others have a go at compiling the
above code(with DJGPP) and see if it works because I have spent ages
trying to debug it and am nowhere near finding an answer. Is it a
compiler problem?
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |