* 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
* Re: Maybe a Bug in Cygwin in using Pointers to class fuctions
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 ` Ward Correll
2 siblings, 1 reply; 6+ messages in thread
From: Mumit Khan @ 1999-08-02 14:18 UTC (permalink / raw)
To: Ward Correll; +Cc: cygwin
"Ward Correll" <wardless@hotmail.com> writes:
> 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.
It's not a bug. Please see the discussion on pointer to member function
in a recent C++ book such as Stroustrup 3rd edition. Of course, the
best place is the ISO standard itself (cf: 8.3.3 [dcl.mptr]/2), but that
can be rather obtuse.
It's also a good idea to report what version of compiler you're using and
some system/OS info (gcc -v reports the compiler version).
> case 1: pFunc = Mammal::Speak; break;
> default: pFunc = Mammal::Move; break;
^^^^^^
> 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?
The compiler gave you the answer, so use it! (hint: Mammal::Speak -->
&Mammal::Speak).
Followup to a C++ forum please.
Regards,
Mumit
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Maybe a Bug in Cygwin in using Pointers to class fuctions
1999-08-02 14:18 ` Mumit Khan
@ 1999-08-31 23:49 ` Mumit Khan
0 siblings, 0 replies; 6+ messages in thread
From: Mumit Khan @ 1999-08-31 23:49 UTC (permalink / raw)
To: Ward Correll; +Cc: cygwin
"Ward Correll" <wardless@hotmail.com> writes:
> 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.
It's not a bug. Please see the discussion on pointer to member function
in a recent C++ book such as Stroustrup 3rd edition. Of course, the
best place is the ISO standard itself (cf: 8.3.3 [dcl.mptr]/2), but that
can be rather obtuse.
It's also a good idea to report what version of compiler you're using and
some system/OS info (gcc -v reports the compiler version).
> case 1: pFunc = Mammal::Speak; break;
> default: pFunc = Mammal::Move; break;
^^^^^^
> 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?
The compiler gave you the answer, so use it! (hint: Mammal::Speak -->
&Mammal::Speak).
Followup to a C++ forum please.
Regards,
Mumit
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Maybe a Bug in Cygwin in using Pointers to class fuctions
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-02 16:40 ` Brendan Simon
1999-08-31 23:49 ` Brendan Simon
1999-08-31 23:49 ` Ward Correll
2 siblings, 1 reply; 6+ messages in thread
From: Brendan Simon @ 1999-08-02 16:40 UTC (permalink / raw)
To: Ward Correll; +Cc: cygwin
Ward Correll wrote:
> =========================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.
Give this a try. It seems GCC is picky about the address of a function and/or
member function. It wants you to explicitly use the address operator as shown
below. I think this should work.
case 1: pFunc = &Mammal::Speak; break;
default: pFunc = &Mammal::Move; break;
Brendan Simon.
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Maybe a Bug in Cygwin in using Pointers to class fuctions
1999-08-02 16:40 ` Brendan Simon
@ 1999-08-31 23:49 ` Brendan Simon
0 siblings, 0 replies; 6+ messages in thread
From: Brendan Simon @ 1999-08-31 23:49 UTC (permalink / raw)
To: Ward Correll; +Cc: cygwin
Ward Correll wrote:
> =========================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.
Give this a try. It seems GCC is picky about the address of a function and/or
member function. It wants you to explicitly use the address operator as shown
below. I think this should work.
case 1: pFunc = &Mammal::Speak; break;
default: pFunc = &Mammal::Move; break;
Brendan Simon.
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Maybe a Bug in Cygwin in using Pointers to class fuctions
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-02 16:40 ` Brendan Simon
@ 1999-08-31 23:49 ` Ward Correll
2 siblings, 0 replies; 6+ messages in thread
From: Ward Correll @ 1999-08-31 23:49 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).