Hi,
I'm trying to get a pointer to a specific version of an overloaded member function. Here's the example:
class C
{
bool f(int) { ... }
bool f(double) { ... }
bool example()
{
// I want to get the "double" version.
typedef bool (C::*MemberFunctionType)(double);
MemberFunctionType pointer = &C::f; // <- Visual C...
I have a class that I've been provided that I really don't want to change, but I do want to extend. I'm a pattern and template newbie experimenting with a Decorator pattern applied to a template class. Template class contains a pointer-to-member (if I understand the semantics correctly) in yet another class. The pointer-to-member is t...
Hi!
I'm try to store member function pointers by templates like this. (This is a simplified version of my real code)
template<class Arg1>
void connect(void (T::*f)(Arg1))
{
//Do some stuff
}
template<class Arg1>
void connect(void (T::*f)())
{
//Do some stuff
}
class GApp
{
public:
void foo() {}
void foo(double ...
What are the various options to implement a pointer-to-member construct in C++/CLI?
I have implemented some 2D geometry algorithms which perform some actions based on X and Y co-ordinates. I find that I am frequently duplicating code once for the X-axis and once for the Y-axis. An example is finding the maximum and minimum bounds along ...
Following code does NOT work, but it expresses well what I wish to do. There is a problem with the template struct container, which I think SHOULD work because it's size is known for any template argument.
class callback {
public:
// constructs a callback to a method in the context of a given object
template<class C>
callback(...
The following callback class is a generic wrapper to "callable things". I really like its API, which has no templates and is very clean, but under the hood there is some dynamic allocation which I was not able to avoid.
Is there any way to get rid of the new and delete in the code below while maintaining the semantics and API of the cal...
Hello Stackoverflow,
I'm currently using GCC 4.4, and I'm having quite the headache casting between void * and a pointer to member function. I'm trying to write an easy-to-use library for binding C++ objects to a Lua interpreter, like so:
LuaObject<Foo> lobj = registerObject(L, "foo", fooObject);
lobj.addField(L, "bar", &Foo::bar);
...
This is a poll for opinions on the most readable way to do something -- whether to use a C++ pointer-to-member, a byte offset, or a templatized functor to define "select member X from structure foo".
I've got a type that contains a large vector of structures, and I'm writing a utility function that basically operates as a reduce over s...
Consider the following code:
template<class T, class F> struct X {};
template<class T, class F, T F::* m> struct Y {};
struct Foo {
int member;
typedef X<int, Foo> x_type; // works well
typedef Y<int, Foo, &Foo::member> y_type; // ERROR
};
typedef Y<int, Foo, &Foo::member> y_type2; // OK
Why does ...
Consider the following code
template<typename T, int N>
struct A {
typedef T value_type; // OK. save T to value_type
static const int size = N; // OK. save N to size
};
Look, it is possible to save any template parameter if this parameter is a typename or an integer value. The thing is that pointer to member is an offset, i.e. int...
Based on other my question.
Consider the following code
template<typename T, int N>
struct A {
typedef T value_type; // save T to value_type
static const int size = N; // save N to size
};
Look, I can use value_type and size as template parameter.
typedef A<int, 2> A1;
typedef A<A1::value_type, A1::size + 3> A2; // OK, A2 is A...
Given the following code which I can't get to compile.
template < typename OT, typename KT, KT (OT::* KM)() const >
class X
{
public:
KT mfn( const OT & obj )
{
return obj.*(KM)(); // Error here.
}
};
class O
{
public:
int func() const
{
...
I'm having this problem for quite a long time - I have fixed sized 2D array as a class member.
class myClass
{
public:
void getpointeM(...??????...);
double * retpointM();
private:
double M[3][3];
};
int main()
{
myClass moo;
double *A[3][3];
moo.getpointM( A ); ???
A = moo.retpointM(); ???
...
Hi, I have this class:
class IShaderParam{
public:
std::string name_value;
};
template<class TParam>
class TShaderParam:public IShaderParam{
public:
void (TShaderParam::*send_to_shader)( const TParam
TShaderParam():send_to_shader(NULL){}
TParam value;
void up_to_shader();
};
typedef TShaderParam<float> FloatShaderParam;
typedef ...
I want to have a structure token that has start/end pairs for position, sentence, and paragraph information. I also want the members to be accessible in two different ways: as a start/end pair and individually. Given:
struct token {
struct start_end {
int start;
int end;
};
start_end pos;
start_end sent;
start_end p...
Consider the following code:
struct Foo
{
mutable int m;
template<int Foo::* member>
void change_member() const {
this->*member = 12; // Error: you cannot assign to a variable that is const
}
void g() const {
change_member<&Foo::m>();
}
};
Compiler generates an error message. The thing is that th...
Given an example class:
class Fred
{
public:
Fred()
{
func = &Fred::fa;
}
void run()
{
int foo, bar;
*func(foo,bar);
}
double fa(int x, int y);
double fb(int x, int y);
private:
double (Fred::*func)(int x, int y);
};
I get a compiler error at the line calling the member function through the pointer "*func(foo,bar)", ...
I am new to pointer to member functions, and I would like to know their pros and cons.
Specifically, consider this:
#include <iostream>
#include <list>
using namespace std;
class VariableContainer;
class Variable
{
public:
Variable (int v) : value (v), cb_pointer (0) {}
~Variable () {}
void SetCallback (void (VariableContaine...
$4.11/2 states -
An rvalue of type “pointer to member
of B of type cv T,” where B is a class
type, can be converted to an rvalue of
type “pointer to member of D of type
cv T,” where D is a derived class
(clause 10) of B. If B is an
inaccessible (clause 11), ambiguous
(10.2) or virtual (10.1) base class of
D, a progra...
In following code consider the statement :- "int B::*bpm;"
class B
{
public :
int bi;
};
class D : public B
{
};
int main()
{
D obj;
int B::*bpm;
bpm = &B::bi;
obj.*bpm = 1;
return 0;
}
When to use "Pointer to members" in design/code to improve my design/coding practice.
*
...