member

member function as callback

六月ゝ 毕业季﹏ 提交于 2019-12-11 08:26:12
问题 I would like to pass a member function of an instantiated object to another function. Example code is below. I am open for any strategy that works, including calling functional() from another function inside memberfuncpointertestclass using something like lambda or std::bind. Please note that I did not understand most of the threads I found with google about lambda or std::bind, so please, if possible, keep it simple. Also note that my cluster does not have C++ 11 and I would like to keep

Pointer to a member-function

旧城冷巷雨未停 提交于 2019-12-11 04:53:14
问题 I would like to do the following: I have two classes, A and B, and want to bind a function from A to a function from B so that whenever something calls the function in B, the function from A is called. So basically, this is the scenario: ( important A and B should be independent classes) This would be class A: class A { private: // some needed variables for "doStuff" public: void doStuff(int param1, float *param2); } This is class B class B { private: void callTheFunction(); public: void

How to enumerate all member variables of a class / struct in c++

我只是一个虾纸丫 提交于 2019-12-11 04:17:13
问题 I'm working on some kind of simple reflection for c++ structs where i want to recursivly iterate over all member variables. The code below almost does what i want but my compiler complians: "recursive type or function dependency context too complex" coming form aggregate_arity<MemberType>::size() which is based on Orients aggregate_arity implementation. Example usage case: struct B { SPVStruct; var_t<float2_t, true> f4; }; struct A { SPVStruct; var_t<float2_t, true> f2; var_t<float3_t, true>

Prolog - Count all patient's symptoms

倖福魔咒の 提交于 2019-12-11 03:12:15
问题 I'm trying to count all patient's symptoms to calculate the certainty factor for the disease, but I'm just getting one symptom of each disease. Also the result shows some duplicates. The certainty factor is the number of patient's symptoms/the total of symptoms of the disease: start:- write('Enter the name of the patient: '), read(Patient), write('Enter the symptoms: '), read(Symptoms), write('\n'), countSint(Diseases, Symptoms , Patient). countSint(Diseases, Symptoms , Patient) :- findall

Object and struct member access and address offset calculation

假如想象 提交于 2019-12-11 02:24:40
问题 I am writing a simple VM and I have a question on implementing object and structure member access. Since the begin address of a program is arbitrary on each run, and subsequently the address of each and every of its objects is arbitrary too. Thus the only way I can think of to access an object or its member object is by accessing an offset from the "base" pointer, which means there is an arithmetic operation needed to access anything in a program structure. My question is whether this is the

debug websocket++ broadcast_server.cpp ('owner_less' is not a member of 'std')

丶灬走出姿态 提交于 2019-12-11 00:23:12
问题 Zaphoyd's broadcast_server.cpp looks like the perfect backbone for a websocket server that it can quickly accept and send messages & connections with a thread for the real action so not to interrupt the communications. https://github.com/zaphoyd/websocketpp/blob/experimental/examples/broadcast_server/broadcast_server.cpp His simple print_server.cpp example compiles easily; however, I'm getting a few compile errors with broadcast_server.cpp . root@server:~# g++ -O3 broadcast_server.cpp -I ~

error C2244 on templated member variable with templated argument function, only happens on Visual Studio

末鹿安然 提交于 2019-12-10 23:31:45
问题 I ran into an interesting, yet extremely annoying, bug on Visual Studio, below is the simplest repro: (uncomment the #define will allow VS to build the code) #include <iostream> using namespace std; //#define BUILD_ON_VS class CC { public: template<typename T> struct Foo { template<T foo> void bar() { cout << "VC likes this!\n"; } #ifndef BUILD_ON_VS template<T foo> void bar1(); #endif }; Foo<int> m_foo; }; #ifndef BUILD_ON_VS template<typename T> template<T foo> void CC::Foo<T>::bar1() {

F#: Attempt to memoize member function resets cache on each call?

六眼飞鱼酱① 提交于 2019-12-10 22:00:12
问题 I'm trying to memoize a member function of a class, but every time the member is called (by another member) it makes a whole new cache and 'memoized' function. member x.internal_dec_rates = let cache = new Dictionary< Basis*(DateTime option), float*float>() fun (basis:Basis) (tl:DateTime option) -> match cache.TryGetValue((basis,tl)) with | true, (sgl_mux, sgl_lps) -> (sgl_mux, sgl_lps) | _ -> let (sgl_mux, sgl_lps) = (* Bunch of stuff *) cache.Add((basis,tl),(sgl_mux,sgl_lps)) sgl_mux,sgl

Copy or Move Constructor for a class with a member std::mutex (or other non-copyable object)?

橙三吉。 提交于 2019-12-10 19:57:28
问题 class A { private: class B { private: std::mutex mu; A* parent = NULL; public: B(A* const parent_ptr): parent(parent_ptr) {} B(const A::B & b_copy) { /* I thought I needed code here */ } }; public: B b = B(this); //...to make this copy instruction work. // (Copy constructor is deleted, need to declare a new one?) }; I have a class B that is basically a thread-safe task queue. It contains a deque , a mutex , and a condition_variable . It facilitates a consumer/producer relationship between any

In C# How to dynamically specify a member of a object, like obj[“abc”] in PHP

帅比萌擦擦* 提交于 2019-12-10 18:47:13
问题 Say I have a class public class Employee { public string name = ""; public int age = 20; } now I want a function that can dynamically get the value of a specified member of Employee public class Util<T> { public static string GetValue(T obj, string member) { // how to write } } so that I can use it like Employee p1 = new Employee(); string a = Util<Employee>.GetValue(p1, "age"); // a should be "20" How to do it? like access member use obj["???"] in PHP 回答1: Reflection. Take a look here: