I am learning C++ and have a problem with pointers. I want to pass a pointer into my method and assign it a new value. But my pointer is 0 after the method was called. What am I doing wrong? Thanks
#include <iostream>
using namespace std;
class MyObject
{
public:
bool search(int* a)
{
int* test = new int(23);
a = test;
return true;
}
};
MyObject* obj;
void search()
{
int* test = NULL;
obj->search(test);
cout << test << endl;
}
int main(int argc, char *argv[])
{
obj = new MyObject();
search();
}