🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1806

Usage of STL maps with pointers to member functions

#1806
From: Gabriel Sanchez Gutierrez
Date: Tue, 22 Aug 1995 14:01
51 lines
2009 bytes
Hello,

As far as I know, maps are transparent wrt the keys and values stored.
I am trying to maintain a map with pointers to member functions. If I access
the members through normal pointers, all is Ok. But if I use the dictionary,
it seems it is not properly initialized.

Any hint?

#include <iostream.h>
#include <map.h>

typedef char* string;

class Test {
    typedef int  (Test::* pGetM) ();
public:
    int a1;
    int geta1   () {return a1;};

public:
    Test (int a): a1(a) {};
};

main ()
{
    Test t (5);

    Test::pGetM f = Test::geta1;
    
    map<string, Test::pGetM, less<string> > mapMethods;
    mapMethods["a1"]  = f; 

    cout << "Attribut = " << t.a1 << endl
	 << "By map   = " << (t.*f)() << endl;

    cout << "Attribut = " << t.a1 << endl
	 << "By map   = " << (t.*mapMethods["a1"])() << endl;
}


-- 
--------------------------------------------------------------------------
Gabriel Sanchez Gutierrez | Phone:        +34.1.327.28.28 x204
DIS - Sema Group sae      | Fax:          +34.1.754.32.52
Albarracin, 25            | Email:        gsg@sema.es
28037 Madrid - SPAIN      | WWW:          http://www.sema.es/~gsg
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <9508221303.AA23723@granados.sema.es>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 22 Aug 95 14:01:37 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Return-Path: <daemon@ncar.UCAR.EDU>
Message-ID: <9508221303.AA23723@granados.sema.es>
X-Original-Date: Tue, 22 Aug 95 15:03:05 0200
Sender: gsg@sema.es
From: Gabriel Sanchez Gutierrez <gsg@sema.es>
Organization: Sema Group sae - DIS
X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.3 sun4m)
Mime-Version: 1.0
Subject: Usage of STL maps with pointers to member functions
X-Url: news:comp.std.c++
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii