I am very new myself to C++, but hopefully you will find this helpful (and accurate):
pt = &a; // that should work
pt is a pointer to an object of type A,
&a is the address of an object of type A.
After that line of code pt and &a reference the same value (ie. contain the same address).
Also, after, *pt and "a" are exactly the same value (ie. same address references the same value).
You say you tried "pt = &A", and if you really capitalized the "A", then that is the problem,
but I would have expected a compile time error rather than the seg fault you described.
For the other option you tried:
1 2 3 4
|
*pt = a;
// I would expect a seg fault here,
// because *pt has not been allocated memory to store a value (no space for a copy of a)
// p. 149 of C++ Primer Plus (Stephen Prata) explains this.
|