C++ (Qt)#include <stdio.h> struct CTest { CTest( int & ref ) : mRef(ref) {} void SetRef( int & ref ) { (&mDummy)[1] = &ref; } void Print( void ) const { printf("a = %d (%p)\n", mRef, &mRef); } // data void * mDummy; int & mRef;}; int main( void ) { int i1 = 4; CTest test(i1); test.Print(); int i2 = 7; test.SetRef(i2); test.Print(); return 0;}
C++ (Qt)struct CTest { CTest( int & ref ) : mRef(ref) {}
C++ (Qt)void SetRef( int & ref ) { (&mDummy)[1] = &ref; } // data void * mDummy;
C++ (Qt)template <class T>class rew{public: rew() : ptr(0) {} void set(T & a) { ptr = &a; } T& operator()() { return *ptr; } operator bool() const { return ptr; } private: T* ptr;};
C++ (Qt)class A{public: void setData(int & data) { mData.set(data); } void someMethod() { if (!mData) return; mData() += 123; std::cout << mData() << std::endl; } private: rew<int> mData; int mOther;};