1

I am writing a template class to function as a dynamic array and I am stumbling at one issue and cannot work out what's wrong. I have goggled it and come up with nothing but have fixed one issue that is similar by adding the class name and the variable size but still get these two. Here is the code

template<class Val>
class DynamArray
{
private:
    const int kSegmentSize = 15;
    int countPos;
    Val initial[DynamArray::kSegmentSize];
public:
    DynamArray::DynamArray();
    DynamArray::~DynamArray();
    void DynamArray::PutVal(Val value);
    Val DynamArray::GetVal();
};

The array initial is causing the error to fix the first issue I added the DynamArray:: and the error disappeared but this one remains and I have no idea remaining here is a copy of the full error.

error C2327: 'DynamArray<std::string>::kSegmentSize' : is not a type name, static, or enumerator

Then I get

error C2065: 'kSegmentSize' : undeclared identifier

If anyone has any ideas about this they would be appreciated.

1 Answer 1

1

This

const int kSegmentSize = 15;
Val initial[DynamArray::kSegmentSize];

should be

static const int kSegmentSize = 15;
Val initial[kSegmentSize];

as only static integrals are allowed to specify array size in-class declarations.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that sorted the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.