see my property constructor:

template <typename T>
class property
    T PropertyValue;
    std::function<T(void)> getf;
    std::function<void(T)> setf;

    property(const T &value)

    property(const property &value)  :  PropertyValue(value.PropertyValue) , getf(value.getf)

    property(std::function<T(void)> GetFunction=nullptr,std::function<void(T)> SetFunction=nullptr)

inside a class i have 2 functions:

void SetCaption(string strtext)
        RECT textrect={0};
        HDC txthdc=GetDC(hwnd);
        DrawText (txthdc,strCaption.c_str(),strCaption.size(),&textrect,DT_CALCRECT | DT_LEFT);
        SetWindowPos(hwnd, HWND_TOP, 0, 0, textrect.right-textrect.left,, SWP_NOMOVE);

    string GetCaption()
        return strCaption;

heres how i create the property:
(to complex yes :( )

property <string> caption{std::bind(&tooltip::GetCaption, *this),std::bind(&tooltip::SetCaption, *this, std::placeholders::_1)};

no error message. but my application gives me an error(no message.. just tells me that the programs stops) and the OS closes the program.
what i'm doing wrong?

Nothing complex just a typo/minor miss-understanding.
You wrote this:

property <string> caption{std::bind(&tooltip::GetCaption, *this),std::bind(&tooltip::SetCaption, *this, std::placeholders::_1)};

Note the *this , that should be just : this. You are trying to binding a class method pointer to a class instance pointer. If the class instance pointer is no such thing then things go wrong. You can use a reference but you convert it with std::ref( X ) which is a bit odd looking if you already have the pointer this!

If we take your orginal protery class and add two methods:

std::string Get() const { return getf(); }
void Set(const std::string& Input) { setf(Input); }

We can write:

class testCase
  std::string Hold;


  testCase() : Hold("WRONG") {}

  void setCaption(const std::string& Out)
    { std::cout<<"SetCaption "<<Out<<std::endl;
      Hold=Out; }

  std::string getCaption() const { return Hold; }

  void build() {
    property <std::string> captionInner

    return; }

int main()
   testCase A;;

Not that you can try with *this and see the wrong result -- however I believe this is undefined behaviour -- no 100% sure.

for correct it i nust take off the '*' pointer operator and i create precompiled routines:

#define GetProperty(x) std::bind(&x, this)
#define SetProperty(x) std::bind(&x, this, std::placeholders::_1)

//how use it:
property <string> caption{GetProperty(tooltip::GetCaption),SetProperty(tooltip::SetCaption)};

thanks for all

This article has been dead for over six months. Start a new discussion instead.