member-pointers

How to cast member variable pointer to generic type in C++

I have code similar to this in my application: class A { public: int b; } class C { public: int d; } void DoThings (void *arg1, MYSTERYTYPE arg2); A obj_a; C obj_c; DoThings(&obj_a, &A::b); DoThings(&obj_c, &C::d); The question is - What should MYSTERYTYPE be? neither void* nor int work, despite the value &A::b being printed j...

is there a use for &func or class::func in c++ ?

This seems inconsistent. Why do we use &Example::func instead of Example::func? is there a use for Example::func or &exampleFunction? it doesnt seem like we can make a reference to a function so that rules out Example::func. and i cant think of a way to use &exampleFunction since exampleFunction already returns a pointer. #include <iost...

Is it standard C++ to assign a member pointer to the address of another member in the constructor initializer?

Does this conform to the standard? class Foo { Bar m_bar; Bar * m_woo; public: Foo() : m_bar(42, 123), m_woo(&m_bar) { } }; ...

member function pointer which returns same type of member function pointer

Hello, I'd like to declare a member function pointer in C++, that returns the same member function pointer type This doesn't work: class MyClass { public: typedef FunctionPtr (MyClass::*FunctionPtr)(); } Does someone know a solution? ...

Nested data member pointer - not possible?

The foolowing reduced code sample does not do anything usefull but two subsequent assignments to a data member pointer. The first assignement works, the second one gives a compiler error. Presumably because its to a nested member. Question would be: Is it really just not possible to let a member pointer point to a nested member or am I ...

Type of pointer to member from base class

I have a problem regarding member pointers. The following code fails to compile using both Oracle Solaris Studio 12.2's CC and cygwin GCC 4.3.4 but works with Microsoft Visual C++ 2010: struct A { int x; }; struct B : public A { }; template<typename T> class Bar { public: template<typename M> void foo(M T::*p); }; int main(int, c...

Member function pointer

If the following from the C++ FAQ Lite is true: "a function name decays to a pointer to the function" (as an array name decays to a pointer to its first element); why do we have to include the ampersand? typedef int (Fred::*FredMemFn)(char x, float y); FredMemFn p = &Fred::f; And not just: typedef int (Fred::*FredMemFn)(char x, flo...