I'm trying to do something like this in my Obj class:
public:
    template <typename T>
    Obj(T & o) {
        siz = sizeof(o);
        p = malloc(siz);
        memcpy(p, &o, siz);
    }   
private:                                
    void * p;
    size_t siz;
That works fine if i do something like this:
string str = "foobar";
Obj u = Obj(str);
but not if I do something like this:
Obj u = Obj(string("foobar"));
That results in a string filled with random characters.
To retreive the string I use:
string S() {
    return *((string *)p);
}
Any idea?
 
     
     
    