Customise my static without a ctor
-
I'll get a static initialised without a explicit ctor if it kills me! header:
struct client {
static client dummy;
std::string username;
int id; // 0+ OK
}cpp:
// Static definition
client client::dummy = std::move(*[=] { client * c = new client();
c->username = "";
c->id = -1;
return c;
}()
);I'm not going to use this code but I wonder about it... memory leak?
-
I'll get a static initialised without a explicit ctor if it kills me! header:
struct client {
static client dummy;
std::string username;
int id; // 0+ OK
}cpp:
// Static definition
client client::dummy = std::move(*[=] { client * c = new client();
c->username = "";
c->id = -1;
return c;
}()
);I'm not going to use this code but I wonder about it... memory leak?
-
And you are sure you didn't miss a way to write it more unreadable? ;P :laugh:
It does not solve my Problem, but it answers my question
-
I'll get a static initialised without a explicit ctor if it kills me! header:
struct client {
static client dummy;
std::string username;
int id; // 0+ OK
}cpp:
// Static definition
client client::dummy = std::move(*[=] { client * c = new client();
c->username = "";
c->id = -1;
return c;
}()
);I'm not going to use this code but I wonder about it... memory leak?
Why does the struct have to have a static copy of itself in it? Why can't you just do:
struct client {
std::string username;
int id; // 0+ OK
}static client theInstance;
theInstance.username = "";
... -
Why does the struct have to have a static copy of itself in it? Why can't you just do:
struct client {
std::string username;
int id; // 0+ OK
}static client theInstance;
theInstance.username = "";
...