Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[C++/STL] pointer to member function!? about <map>....

0 views
Skip to first unread message

堅忍卓絕

unread,
Apr 24, 2000, 3:00:00 AM4/24/00
to
請問C++高手:

#include <map>
using namespace std;
map<KEY,VALUE> table;

請問我要怎麼把VALUE設為一個pointer to member function呢?

我的想法是這樣子...

TEST class{
map<string,bool(TEST::*)(char)> table;
//...
bool foo(char);
//...

};

這樣在GNU C++ 上可以compile,但是C++ Builder 4.X 上過不了...
有人知道該如何正確宣告嗎?

P.S C++ Builder 4.x 給予這個宣告的錯誤訊息

Identifier expected
Expression syntax
Cannot generate template specialization from 'map<Key,T,Compare,Allocator>'
Declaration terminated incorrectly

--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>

jjhou

unread,
Apr 24, 2000, 3:00:00 AM4/24/00
to

>發信人: Leesu...@cis.nctu.edu.tw (堅忍卓絕), 看板: oop
>標 題: [C++/STL] pointer to member function!? about <map>....
>發信站: 交大資科_BBS (Mon Apr 24 09:48:41 2000)
>轉信站: maple!news.cs.nthu!news.cis.nctu!cis_nctu
>Origin: tnt-19.ks.edu.tw


>
>請問C++高手:
>
> #include <map>
> using namespace std;
> map<KEY,VALUE> table;
>
> 請問我要怎麼把VALUE設為一個pointer to member function呢?
>
> 我的想法是這樣子...
>
> TEST class{
> map<string,bool(TEST::*)(char)> table;
> //...
> bool foo(char);
> //...
>
> };
>
> 這樣在GNU C++ 上可以compile,但是C++ Builder 4.X 上過不了...
> 有人知道該如何正確宣告嗎?
>
>P.S C++ Builder 4.x 給予這個宣告的錯誤訊息
>
> Identifier expected
> Expression syntax
> Cannot generate template specialization from 'map<Key,T,Compare,Allocator>'
> Declaration terminated incorrectly

// vc6[o] bcb4[o] g++2.91.57[o]
#include <map>
#include <string>
using namespace std;

// BCB 要求需先有 typedef. (不合理的要求)
// VC6 和 G++ 允許直接為 map 指定 type of pointer to member function.
class A {
typedef bool (A::*MemFuncPtr)(char);
map<string, MemFuncPtr> table;
};

int main()
{
}

-- jjhou

--
※ Origin: 楓橋驛站<bbs.cs.nthu.edu.tw> ◆ Mail: jj...@ccca.nctu.edu.tw

0 new messages