I have the following C++ class:
class Eamorr {
public:
redispp::Connection conn;
Eamorr(string& home, string& uuid)
{
//redispp::Connection conn("127.0.0.1", "6379", "password", false); //this works, but is out of scope in put()...
conn=new redispp::Connection("127.0.0.1", "6379", "password", false); //this doesn't work ;(
}
put(){
conn.set("hello", "world");
}
...
}
As you can see, I want conn to be initialised in the constructor and available in the put() method.
How can I do this?
Many thanks in advance,
This is what member-initialization-list is for:
The syntax after
:( and including this) forms member-initiazation-list. You can initialize the members here, each member separated by comma.Here is an elaborated example:
For more, see these: