Hello all, I'm a beginner to C++ and having trouble with an assignment. I keep getting the error "Expression must be a modifiable lvalue". The program I'm writing is a simple letter frequency counter, where the user inputs a file and the program counts and stores the occurrences of each letter. I know how I would go about this using a fixed size array but the requirements for the prog is that I must use a dynamic array template which functions like a vector (which i have already created) with the typename of a struct containing the data.
dynamicArray is basically a class that functions much like a vector. It stores an allocated array of items.
Here is my header file for it, i can post the implementation too but it is quite long. Name is darray.
You have two operator[] with the only difference being the return type.
I thought this would not compile but I guess your compiler picks the version that returns a const reference and that's probably why you can't assign to it.
To fix this problem you should mark the const version as const.