C++ pointer arrays as static class members
Hello everyone.
So i can get this code to work:
Code:
#include <iostream>
using namespace std;
class test
{
public:
test(){}
~test(){}
void printInts()
{
locPtr = pointer;
for (int i=0; i<5; i++)
{
cout<<*locPtr;
locPtr++;
}
}
private:
static int* pointer;
int* locPtr;
static int* getInts()
{
int* intPtr = new int[5];
for (int i=0; i<5; i++)
intPtr[i] = i;
return intPtr;
}
};
int *test::pointer = test::getInts();
int main ()
{
test a;
a.printInts();
return 0;
}
Now i would like to use the same convention but with being a pointer array like this:
Code:
#include <iostream>
using namespace std;
class test
{
public:
test(){}
~test(){}
void printInts()
{
locPtr = pointer[1];
for (int i=0; i<5; i++)
{
cout<<*locPtr;
locPtr++;
}
}
private:
static int* pointer[2];
int* locPtr;
static int* getInts()
{
int* intPtr = new int[5];
for (int i=0; i<5; i++)
intPtr[i] = i;
return intPtr;
}
};
int *test::pointer[1] = test::getInts();
int main ()
{
test a;
a.printInts();
return 0;
}
,which i know doesn't work. Please could you share any ideas of how I could make the latter code compile. Thanks