Hello everyone.
So i can get this code to work:
Now i would like to use the same convention but withCode:#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; }being a pointer array like this:Code:test::pointer
,which i know doesn't work. Please could you share any ideas of how I could make the latter code compile. ThanksCode:#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; }