Topic: ??? Valid use of ptr to mem fn ???


Author: kaelin@bridge.com (Kaelin Colclasure)
Date: 18 May 1994 05:19:44 GMT
Raw View
I'd like to know if the following is valid C++ (specifically, the line
bracketed by "#ifndef __GNUG__"):

--- file problem.cc ---
#include <iostream.h>

class Base {
public:
   void fizzle();
};

class Derived : public Base {
public:
   void frob();
};

typedef void (Base::*MethodPtr)();

MethodPtr default_action = &Base::fizzle;

void Base::fizzle()
{
   cout << "Fizzle..." << endl;
}

void Derived::frob()
{
   cout << "Frob..." << endl;
}

int main(int argc, char **argv)
{
   Derived rendezvous;

#ifndef __GNUG__
   default_action = (MethodPtr)&Derived::frob;
#endif
   (rendezvous.*default_action)();
   return 0;
}
--- eof problem.cc ---

As you might guess from the surrounding preprocessor directives, g++
has a problem with the line in question.  It reports the following:

problem.cc: In function `int main(int, char **)':
problem.cc:33: conversion to non-scalar type requested

However, two other CFront based compilers (CenterLine and SparcWorks
[old]) accept the cast and the code executes intuitively.  Is this an
omission/bug in g++ or a hole in CFront?  What does the draft standard
have to say about this situation?

I apologize if this is a repost...  My earlier post appears to have
dissappeared, but will probably materialize as soon as this one is
sent on its way. :-)
--
// Kaelin Colclasure ---------------------------------------------------------
// EMail: kaelin@bridge.com            Mail: Bridge Information Systems, Inc.
// Voice: (314)567-8463                      717 Office Parkway
//   Fax: (314)432-5391                      St. Louis, MO 63141