Sorry in advance as I am a novice. I'm struggling with pointers in general, and this case is no different. When I call my getter that's supposed to output elements of an array, I get a random long integer that changes every time I run the program. I know the code is all over the place. I took out as much as possible to keep it short, but let me know if more is needed.
Class Class1 {
public:
const static int SIZE = 4;
// Actual project is split .h and .cpp
Class1() {
for (int i = 0; i < SIZE; ++i) {
numThings[i] = 0;
}
}
Class1(int* thingsPtr) {
SetNumThings(thingsPtr);
}
void SetNumThings(int numThings[]) {
for (int i = 0; i < SIZE; ++i) {
this->numThings[i] = numThings[i];
}
}
int GetNumThings() {
return *thingsPtr;
}
// Calling GetNumThings() in my Print() function outputs garbage
private:
int numThings[SIZE];
int* thingsPtr = numThings;