Article View: gnu.g++.help
Article #793Casting Member Function Pointers
From: Dennis Brake
Date: Tue, 17 Oct 1995 14:23
Date: Tue, 17 Oct 1995 14:23
71 lines
1466 bytes
1466 bytes
I'm trying to get the following code to compile with gcc version 2.5.8.
This code has been compiled using both the Sun C++ compiler and the
ObjectStore compiler. The problem occurs in the arguments to the
function "setMbrFcn." The casting to a MbrFcn is required for the other
compilers. Any help or suggestions would be appreciated.
Thanks
Dennis
atl> gcc -c test.cc
test.cc: In method `Foo::Foo()':
test.cc:34: conversion to non-scalar type requested
test.cc: In method `Bar::Bar()':
test.cc:48: conversion to non-scalar type requested
file: test.cc
class Foo;
typedef void (Foo::*MbrFcn) (void*);
class Foo
{
public:
Foo ();
protected:
void setMbrFcn (MbrFcn mbf);
private:
MbrFcn mbrfcn;
void fooFunction (void*);
};
class Bar : public Foo
{
public:
Bar ();
protected:
void barFunction (void*);
};
Foo::Foo ()
{
setMbrFcn ((MbrFcn)&Foo::fooFunction);
}
void Foo::setMbrFcn (MbrFcn mbf)
{
mbrfcn = mbf;
}
void Foo::fooFunction (void*)
{
}
Bar::Bar ()
{
setMbrFcn ((MbrFcn)&Bar::barFunction);
}
void Bar::barFunction (void*)
{
}
Technical Details
Message-ID:
<460e8c$8v5@linus.mitre.org>Path:
arc1-ca.pugleaf.net!linus.mitre.org!atl!dbrakeShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!linus.mitre.org!atl!dbrake From: dbrake@atl.mitre.org (Dennis Brake) Newsgroups: gnu.g++.help,comp.lang.c++ Subject: Casting Member Function Pointers Date: 17 Oct 1995 14:23:08 GMT Organization: Mitre Corporation, McLean, VA Message-ID: <460e8c$8v5@linus.mitre.org> NNTP-Posting-Host: atl.mitre.org