C++: Global variable as pointer
I am new to c++ and have one question to global variables. I see in many
examples that global variables are pointers with addresses of the heap. So
the pointers are in the memory for global/static variables and the data
behind the addresses is on the heap, right?
Instead of this you can declare global (no-pointer) variables that are
stored the data. So the data is stored in the memory for global/static
variables and not on the heap.
Has this solution any disadvantages over the first solution with the
pointers and the heap?
Edit:
First solution:
//global
Sport *sport;
//somewhere
sport = new Sport;
Second solution:
//global
Sport sport;
No comments:
Post a Comment