Conversion Constructor and Pointers Help

This is a discussion on Conversion Constructor and Pointers Help within the C++ Programming forums, part of the General Programming Boards category; Hello group!!This is my first thread here,so bear with me.. I have been assigned a program to study about pointers ...

Conversion Constructor and Pointers Help

Hello group!!This is my first thread here,so bear with me.. I have been assigned a program to study about pointers and constructors all at once and since i am a beginner,i am not able to figure out how this program works.
:

"this" is a pointer that is present in all classes and basicly points to the instance of the object you are calling the method from and can only be used within memberfunctions of a class. That line is equivalent to writing a=x, no difference but some people like to type out this->a to make it more apparent that you are working on a member variable or calling a member function.

Edit: Also it is pure luck that your code actually works and does not crash. You have a pointer that isnt initialized to any memory at, yet used and assigned to. This is very dangerous and has caused alot of problems for alot of programs where they "suddenly stop working".

And last but not least, you are using non-standard c++ headers and any modern compiler should warn you or give you errors for those. iostream.h should be iostream, don't need alloc.h and the only reason you have conio.h is for clrscr which is also nonstandard. I would suggest you upgrade to a compiler that warns or gives you errors for these things. 2 Suggestions i have are http://www.codeblocks.org/ and http://www.microsoft.com/visualstudi...itions/express

Yes I also noticed immediately that the code both assigns to and reads from an uninitialised pointer.

My advice was going to be to step through the program one line at a time using the debugger and look around at what is called and what is changed as it runs. However, if you try and run that program then it will most likely just crash.

Pointers do not actually allocate objects. Just as their names imply, they "point" to things. So to actually use a pointer, you must first point it to some valid memory location.
This can be done in several ways. But you can, for example, do b = &a to take the address of a and have b point to it. At that point forward, you can manipulate b as you wish.
Keep this in mind.
Also, better indentation wouldn't hurt.