- #1
Silicon Waffle
- 160
- 203
Yesterday I learned about new and delete in my teacher lecture.
I have a function that looks like this
The function works
but if I rewrite it as
then I have an exception. And if I use a reference like this
I also have an exception as boot is empty.
I have a function that looks like this
PHP:
string func()
{
//...
sometype * boot=new sometype();
// do something with boot
string s=boot->getStr();
return s;
}
The function works
but if I rewrite it as
PHP:
string func()
{
//...
sometype * boot=new sometype();
// do something with boot
string s=boot->getStr();
delete boot;
return s;
}
then I have an exception. And if I use a reference like this
PHP:
string func()
{
//...
sometype boot;
// do something with t
string s=boot.getStr();
return s;
}
I also have an exception as boot is empty.
Last edited: