🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac.programmer.codewarrior
Article #30

templatized pointers to member functions (in CW8)

#30
From: R Shapiro
Date: Thu, 01 Feb 1996 13:33
48 lines
1653 bytes
I need to reference a pointer to a member function within a template,
where the class of the function is determined by the template parameter.

Consider:

#include <iostream.h>

class ATest {
   typedef void (ATest::*ATestObjectMemberFunction)(void);
   public:
      ATest() {}
      void junk () { cout << "Junk" << endl << flush;}
      ATestObjectMemberFunction func () { return &ATest::junk; }
};

template <class OBJECT>
class Test {
   // (a) This is what I want but it won't compile in CodeWarrior 8:
   //typedef void (OBJECT::*ObjectMemberFunction)(void); 

   // (b) This works but isn't what I want:
   typedef void (ATest::*ObjectMemberFunction)(void); 
   
   private:
      OBJECT& object;
      
   public: 
      Test(OBJECT& object) : object(object) {}
      void run(ObjectMemberFunction func) { (object.*func)(); }
};     


int main ()
{
   ATest aTest;
   Test<ATest> aTestTemp (aTest);
   
   aTestTemp.run(aTest.func());
   return 0;
}

My first question is, should (a) work? A reading of Stroustrup doesn't
make this clear, at least not to me. Second question: if it shouldn't, is
there another way to do what I'm after here? Third question, for
Metrowerks: if it should work, do you plan to support it soon?

-- 
rs/rshapiro@bbn.com
Technical Details
Message-ID: <rshapiro-0102960833080001@ipa.bbn.com>
Path: arc1-ca.pugleaf.net!ipa.bbn.com!user

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!ipa.bbn.com!user
From: rshapiro@bbn.com (R Shapiro)
Newsgroups: comp.sys.mac.programmer.codewarrior,comp.lang.c++
Subject: templatized pointers to member functions (in CW8)
Date: Thu, 01 Feb 1996 08:33:07 -0500
Organization: Bolt Beranek & Newman
Message-ID: <rshapiro-0102960833080001@ipa.bbn.com>
NNTP-Posting-Host: ipa.bbn.com