Re: auto_ptr not dereferencable
On 28 helmi, 07:23, raof01 <fera_b...@hotmail.com> wrote:
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_b...@hotmail.com
==================
Thoughts are but dreams till their effects be tried.
No worries, I'm quite capable of confusing myself. I appreciate your
efforts.
I'll try to explain a bit better my case also.
The "m_osCom->Initialize(this);" line in the Communicator.cpp calls an
Initialize
function in OsCommunication.cpp file. The Initialize is defined in
OsCommunication.h
file as void Initialize(void *);.
The OsCommunication is an abstract class so I can't
instantiate it straight. So I've done an "typedef OsCommunication
osCom;" in the
Communicator.h file and then define the m_osCom as
std::auto_ptr<osCom> m_osCom; in
the same Communicator.h file.
Then when I get to the "m_osCom->Initialize(this);" line in the
Communicator.cpp
file, I get the error "auto_ptr not dereferencable".
I hope this makes this a bit clearer.
----
mkarja