You need to pass the pointer into the print function as it isn't a global.
static int print(string* pointer)
This should work just fine.
Also, you have a memory leak as your line
string *pointer = new string;
and call it using
print(pointer);
Allocates and never deletes the new string object. You might want to use
string *pointer = nullptr;
Instead. Also, using namespace <whatever>
can lead to issues. Be sure you're doing it for good reasons and not to avoid typing a few extra characters.
EDIT :
As suggested here is a quick run down on scope.
The way to look at scope is kind of like the life of an object and who can see it. An object you create (not using new) has a scope up until it falls out of a block of code. Be that block a function, a conditional statement, or a loop. Further, the object can only be seen by code BELOW where it was created.
void foo()
{
Bar b;
/** really cool code **/
}
Here, object b of type Bar can be seen by the entire function. Once the function ends b "falls out of scope" and automatically has the destructor called on it. NOTE : This does not happen to pointers created with NEW.
void foo()
{
Bar b1;
for(size_t index = 0; index < 10; ++index)
{
/** some cool code **/
Bar b2;
/** some equally cool code **/
}
if(false)
{
Bar b3;
/** some useless code **/
}
/** really cool code **/
}
Here, b1 can be seen by the entire function. b2 can only be seen by the "equally cool code" in the for loop. The "cool code" can't see it because it is declared below it. Finally, b3 never gets seen by anything because the conditional is always false. Once each object "goes out of scope", b1 at the end of the function and b2 at the end of the loop, the system takes care of calling the destructor.
That is the very basics of scope. NOTE : If you EVER use the keyword NEW to create a pointer to an object then you must DELETE that object somewhere. The scope only applies to the pointer (say Bar* b_ptr) and not the object created using NEW.
You would be wise to learn this well, grasshopper.