VC++ bug? member pointers, and member function pointers

Started by
12 comments, last by godecho 15 years, 10 months ago
Quote:Original post by stonemetal
I was thinking -pedantic -std=c++98 .
I think that is more or less what __STRICT_ANSI__ does but I am not sure.


It seems -std=c++98 defines __STRICT_ANSI__ so it is at least equivalent if not more strict. The code still compiles without issue using that switch.
Advertisement
Sounds like a problem in VC++ then. They have always been a little behind when it comes to templates. Most of our cross platform code has macros out the wazoo to work around MS templates. Luckily they all existed before I got here so I didn't have to figure them out. Unfortunately that means I don't know how to help.
Quote:Original post by Emmanuel Deloget
Quote:Original post by jpetrie
So, short version is it looks like it's not legal, from my interpretation.


That would make the implementation of std::tr1::is_member_function_pointer<> and std::tr1::is_member_object_pointer<> a bit difficult, isn't it?

Those both operate on types and use partial specialization on a member [function] pointer type, not a member [function] pointer instance, thus dodging the issue.

14.1.4 legalizes pointers to members and to functions, so presumably member functions are legal. However, my understanding is that template parameters aren't subject to C++'s function overloading rules, and by extension, the original snippet is malformed, since they have the exact same signature, scope, and name. Fortunately, from the other thread, it looks like there's no reason that using actual overloading wouldn't be an option, which VC++9 groks properly:

struct Foo{    int a, b;    int getB() const { return b; }};template <class T> struct Bar{    template < typename M > void add( M  T::*m          ) { ... }    template < typename M > void add( M (T::*m)() const ) { ... }};int main(int argc, char** argv){    Bar<Foo> bar;    bar.add( &Foo::a );    bar.add( &Foo::getB );    return 1;}


Alternatively, seperating them out into add and add_f is another option, which is the smallest change you can make to get the original snippet compiling under VC++9.
Quote:Original post by MaulingMonkey
*** Source Snippet Removed ***

Alternatively, seperating them out into add and add_f is another option, which is the smallest change you can make to get the original snippet compiling under VC++9.


Unfortunately by making 'm' a passed variable, it can't be used in templates in the function body.

the original code looked like:

template <typename T, typename M, M const T:: *member>class order_pred {public:    static bool before(const T& left, const T& right)    {        return left.*member < right.*member;    }};...template <typename M, M const T:: *m>void add(){    preds.push_back(order_pred<T, M, m>::before);}


Looks like I'll have to settle for add and add_f.

This topic is closed to new replies.

Advertisement