I have the following code and it wont compile, it says no matching function for call to `autop::autop(autop)' at this part
autop j = f();
I don't understand why the copy constructor wont accept the autop copy Im sending it.
#include <iostream>
using namespace std;
class autop
{
public:
autop(int * s){ p = s ; } //init the protectee
autop(autop & s) { p = s.p ; }
autop & operator=(autop & s){ p = s.p ; } //first indicates a fucking reference
~autop(){delete p;}
int * p;
};
autop f(){
autop p (new int(7));
return p;
}
int main()
{
autop j = f();
system("pause");
}
Another Thing:
when used inside the function parameter list (i.e autop(autop & s) , whats the effect of the &, does it creates a ref, or is it passing an address, is it the same( I dont see how) , how should I understand it.
I also wonder why using & to get the address of anything adds a '*' i.e if I have
int * p
int x;
p = x //wont work AND compiler says: invalid conversion from int to int*
//same applies to
int ** pp;
int * p
pp = p;
so question why adding an & makes the '*' match to the compiler
Does taking the address of anything gives me a pointer or what
:confused: