Re: auto_ptr not dereferencable
Hello mkarja,
On 28 helmi, 07:00, raof01 <fera_b...@hotmail.com> wrote:
Hello mkarja,
"Debug Assertion Failed, auto_ptr not
dereferencable"
please new one instance and is pointed by auto_ptr.
Thank you for the answer, but I'm sorry, I don't understand what you
mean.
Do you mean that I should do something like this:
std::auto_ptr<osCom> m_osCom (new osCom);
I've tried that, but it just gives me an error saying, "error C2059:
syntax error : 'new'"
----
mkarja
Forgot "()"? :-)
std::auto_ptr<osCom> m_osCom (new osCom());
But I think you'd better initialize m_osCom in ctor.
BTW, are you coming from C# community or ?
It gives the same syntax error even with
std::auto_ptr<osCom> m_osCom (new osCom());
Do I have to initialize it somehow in the .h or .cpp file before I try
to use it in the .cpp file?
No, I'm not coming from C#. Just never used auto_ptr before and are a
bit lost with it, it seems :)
----
mkarja
Sorry for confusing you. If osCom doesn't have ctor with no arguments, you
should use another ctor of osCom.
E.g.
You have:
class osCom
{
public: // All kinds of ctor's but without osCom()
osCom(int) { /* ... */ }
osCom(const string &) { /* ... */ }
// ...
};
Then you will use something like below:
std::auto_ptr<osCom> m_osCom (new osCom(0));
or
std::auto_ptr<osCom> m_osCom (new osCom("Hello"));
If you want to initialize it elsewhere, put the initialization into initialization
list of ctor - just a recommendation.
All my code can be compiled by g++ 3.4.4.
WBR,
raof01
mailto:fera_bill@hotmail.com
==================
Thoughts are but dreams till their effects be tried.