Re: Pointer help
On Jul 6, 8:18 pm, BillGill <billne...@cox.net> wrote:
Ok, I assume this has been asked many times, but I can't seem to come up with
a good Google search to find it.
I am trying to learn C++. Specifically I have Microsoft Visual C++ 2005
Express Edition. I am trying to learn it from Ivor Horton's Beginning
Visual C++ 2005.
My problem comes when we get to pointers. I just cannot seem to wrap my
mind around the complexities involved. Is there some place, either a book
or a website that will take me by the hand and lead me carefully through
the maze?
I do understand a lot about programming. I know Visual Basic, but want to
expand my abilities.
Thanks a lot.
Bill
declaring a pointer does NOT invoke a constructor
its just an address that _could_ point to a valid, initialized object
nobody cares what the exact value of the address stored is in the
pointer,
as long as it points to a valid object
In other words, the following generates a seg fault
#include <iostream>
class N
{
int n;
public:
N(int i = 0) : n(i)
{
std::cout << "N()\n";
}
int get() const { return n; }
};
int main()
{
N* ptr; // points to garbage
// N instance;
// ptr = &instance;
std::cout << ptr->get() << std::endl;
}
/*
.... Segmentation Fault ...
*/
/* with commented lines infused... we have success
N()
0
*/