From: Martin Ambuhl Newsgroups: comp.os.msdos.djgpp Subject: Re: C++ problem Date: Thu, 24 Sep 1998 14:10:57 -0400 Organization: Nocturnal Aviation Lines: 53 Message-ID: <360A8B31.53CF31E9@earthlink.net> References: <6udqfn$sdk$1 AT inf6serv DOT rug DOT ac DOT be> NNTP-Posting-Host: 1cust196.tnt12.nyc3.da.uu.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Johan Verschraegen wrote: > > I use gcc from djgpp to compile the following C++ program under DOS. I > get two warnings: (1)assuming & on 'Test::PrintMode0()' and > (2)assuming & on 'Test::PrintMode1()' > There's also an error: (3)in method 'void Test::Print()' > must use .* or ->* to call printer-to-member > function in 'Test::PrintPtr(...)' > When i tried to compile to program with gcc under Unix i got no errors and > the program worked fine. Please help me with how to solve this. Why not just do what the diagnostics suggest, as follows: #include 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; } -- Martin Ambuhl (mambuhl AT earthlink DOT net) Note: mambuhl AT tiac DOT net will soon be inactive