I don't think I have mastered shared_ptr
.
Example code:
shared_ptr<ofstream> logger;
int main(){
logger = make_shared<ofstream>(new ofstream("ttt.txt"));
*logger <<"s";
return 0;
}
Error 1 error C2664: 'std::basic_ofstream<_Elem,_Traits>::basic_ofstream(const char *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'std::basic_ofstream<_Elem,_Traits> ' to 'const char *' c:\program files (x86)\microsoft visual studio 10.0\vc\include\xxshared 13
Edited:
[
In the mean time, if I wanna close the ofstream while some crashes happened.
How can I do it?
I mean if shared_ptr release the memory without closing the file.
There would be problems.
]
I don't know how to make this happen. Or maybe it's nonsense at all. Hope any one can throw an idea or point out the lacking part of my understanding on shared_ptr
.