| | |
auto_ptr implementation v.basic for learning purposes
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 21
Reputation:
Solved Threads: 1
I have the following code and it wont compile, it says no matching function for call to `autop::autop(autop)' at this part
I don't understand why the copy constructor wont accept the autop copy Im sending it.
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
so question why adding an & makes the '*' match to the compiler
Does taking the address of anything gives me a pointer or what
C++ Syntax (Toggle Plain Text)
autop j = f();
I don't understand why the copy constructor wont accept the autop copy Im sending it.
C++ Syntax (Toggle Plain Text)
#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 ****ing 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
C++ Syntax (Toggle Plain Text)
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;
Does taking the address of anything gives me a pointer or what
•
•
Join Date: Jul 2009
Posts: 903
Reputation:
Solved Threads: 144
•
•
•
•
I have the following code and it wont compile, it says no matching function for call to `autop::autop(autop)' at this partC++ Syntax (Toggle Plain Text)
autop j = f();
•
•
•
•
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
so question why adding an & makes the '*' match to the compilerC++ Syntax (Toggle Plain Text)
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;
Does taking the address of anything gives me a pointer or what
int *p = &x is to say "p" points to reference "x". When you try int *p = x , you are attempting to say an address pointer points to an integer value, which is why you get an error because this code is suspect of being in error.Part 2: Your **pp is a pointer to a pointer, so when you dereference "**pp" as *pp, it must be a pointer, but if you want to assign to "**pp", you must assign the equivalent pointer to a pointer. Therefore, you could say
*pp = p , because "p" is a pointer and you are assigning it to a pointer (contents of **pp written as "*p"). Last edited by DdoubleD; Aug 30th, 2009 at 1:48 am. Reason: Part 2
•
•
Join Date: Dec 2008
Posts: 21
Reputation:
Solved Threads: 1
Here are the results
writting
// I didn't quite got what you said in paragraph 2 but thinking it well it helps what you said on first paragraph , Im generalizing this as "any pter(single, pointer to pter, ppp, pppp , jaja... etc )" points to a reference of its pointee
well this so far makes sense but what happens in the next case
it won't compile it says the familiar invalid conversion from int to int*
in this part now I wonder: Why the error. am I not giving the pter a reference to the int alredy!?
BTW about my previous error I can't believe you compiled that without problems, this thing of mine won't let me
writting
C++ Syntax (Toggle Plain Text)
int ** pp; int * p; int v = 5; p = &v; //you say "pointers point to references " *pp = p; //Therefore, you could say *pp = p , because "p" //is a pointer and you are assigning it to a pointer cout << **p; //BUT this crashes when you run the program! //what did work was pp = &p; cout << **p;
// I didn't quite got what you said in paragraph 2 but thinking it well it helps what you said on first paragraph
C++ Syntax (Toggle Plain Text)
pointers point to references
well this so far makes sense but what happens in the next case
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; class ppr{ public: ppr(int & r): p(r){} int * p; }; int main() { int x = 5 ; ppr rr(x); cout << *(rr.p); // shuts system("pause"); }
it won't compile it says the familiar invalid conversion from int to int*
in this part
C++ Syntax (Toggle Plain Text)
ppr(int & r): p(r){}
BTW about my previous error I can't believe you compiled that without problems, this thing of mine won't let me
Last edited by namehere05; Aug 30th, 2009 at 2:59 am.
![]() |
Similar Threads
- Fun Questions... (Python)
- Using auto_ptr or shared_ptr to allocate memory to a structure (C++)
- cyclic codes help (C++)
- need help with atm coding again (Python)
- Icons (Visual Basic 4 / 5 / 6)
- Modern Replacement for Basic (Legacy and Other Languages)
- Switching From Explorer.exe to Progman.exe (Windows NT / 2000 / XP)
- Anybody can help me make a game? (Java)
- multi-boot OS problems trying to boot to C drive I get error mess non sys disk nodisk (Windows NT / 2000 / XP)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: 2d Arrays e FUSSY - Store data in 1d area
- Next Thread: Variable # of args for a class template
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






LOL. That's a lot of PP, so if that was supposed to be a joke you got me.