public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Maybe a Bug in Cygwin in using Pointers to class fuctions
@ 1999-08-02 13:54 Ward Correll
  1999-08-02 14:18 ` Mumit Khan
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ward Correll @ 1999-08-02 13:54 UTC (permalink / raw)
  To: cygwin

Maybe a bug in Cygwin! I think that this sorce code is correct in the Final 
ANSI\ISO standard on C++ so I think it could be cygwin. Please check it out 
for me in this simple code.

//Maybe a bug (in Cygwin) in using a pointer to a class fuction

#include <iostream.h>

class Mammal
{
public:
	Mammal():itsAge(1) {  }
	virtual ~Mammal() { }
	virtual void Speak() const = 0;
	virtual void Move() const = 0;
protected:
	int itsAge;
};

class Dog : public Mammal
{
public:
	void Speak()const { cout << "Woof!\n"; }
	void Move() const { cout << "Walking to heel...\n"; }
};


class Cat : public Mammal
{
public:
	void Speak()const { cout << "Meow!\n"; }
	void Move() const { cout << "slinking...\n"; }
};


class Horse : public Mammal
{
public:
	void Speak()const { cout << "Winnie!\n"; }
	void Move() const { cout << "Galloping...\n"; }
};


int main()
{
	void (Mammal::*pFunc)() const =0;
	Mammal* ptr =0;
	int Animal;
	int Method;
	bool fQuit = false;

	while (fQuit == false)
	{
		cout << "(0)Quit (1)dog (2)cat (3)horse: ";
		cin >> Animal;
		switch (Animal)
		{
		case 1:	ptr = new Dog; break;
		case 2: ptr = new Cat; break;
		case 3: ptr = new Horse; break;
		default: fQuit = true; break;
		}
		if (fQuit)
			break;

		cout << "(1)Speak  (2)Move: ";
		cin >> Method;
		switch (Method)
		{
		case 1: pFunc = Mammal::Speak; break;
		default: pFunc = Mammal::Move; break;
		}

		(ptr->*pFunc)();
		delete ptr;
	}
	return 0;
}

=========================OUTPUT FROM CYGWIN==========================
BASH.EXE-2.02$ c++ -o try try.cpp
test.cpp: In function `int main()':
test.cpp:66: assuming & on `Mammal::Speak'
test.cpp:67: assuming & on `Mammal::Move'
=====================================================================
I know I want the fuction pointer to assume on Mammal::Speak or Mammal::Move 
when meets some conditions as you see. But cygwin won't let me do that.  
Anyway to force compiling?

Thanks!!! if you gave it a try.



_______________________________________________________________
Get Free Email and Do More On The Web. Visit http://www.msn.com

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1999-08-31 23:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-02 13:54 Maybe a Bug in Cygwin in using Pointers to class fuctions Ward Correll
1999-08-02 14:18 ` Mumit Khan
1999-08-31 23:49   ` Mumit Khan
1999-08-02 16:40 ` Brendan Simon
1999-08-31 23:49   ` Brendan Simon
1999-08-31 23:49 ` Ward Correll

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).