erros:
prog.cpp: In function 'int main()':
prog.cpp:24:13: error: invalid conversion from 'int' to 'int*' [-fpermissive]
mmm mobj1(6);
^
prog.cpp:12:2: note: initializing argument 1 of 'mmm::mmm(int*)'
mmm(int *b){
p.s I copied literarily example from tutorial...confused..
Why does the constructor have parameters if the value of it is never used inside the constructor? Even if you want to have parameters, b doesn't have to be a pointer just because a is.
Line 24 seems to call default destructor (one that takes no parameters), but the class mmm does not have one. The compiler does not implicitly generate default constructor, because the class defines explicit constructor (with one parameter).
Line 25 prints a memory address, not a value.
When a class manages dynamic memory, it is not enough to write explicit destructor. You have to consider these too:
* copy constructor
* copy assignment
* move constructor
* move assignment
* default constructor
That is a problem, I am searching for sntax itself. (=without something missing!)
Here is an example, which does not have it all (and btw this example DOES not work ,so I wonder what I miss to make proper code and where to find syntaks or protopype)
Is that theorethically ok, if not why not? So, is it right that I was using destructor because I operated with variable *a, containting value 3, which was placed on
0xdeadbeaf, and if I fnished the code without destructor, I would have memory leak, right?
So, next step would be to write code whose type would be mmm(=class type).
Please, any ideas for pseudocode? (tried to google, but couldn't, do I miss some keywords?)..
Anyhow, what is that destructor (~mmm) destructing? It is acutaly a variable, that it is deleting. We can do an object using that variable, but deleted is what? would say- variable, and CONSEQUENTLY but ONLY consequently object mobj1...am I right? So, ~mmm IS deleting the object mobj1, but CONSEQUENTLY, not directly...hope U understand what I ment, cause now I am trying to write code using class type objects to be stored on the heap...
I tried to make a code in which destructor would prevent memory leak...so please tell me all U think that is not good represented in my code up...thanks!!!