Hi I am looking to initalize whole array to single element in constructor of class.I have tried this solution but I am getting this errror.
1>C:\Users\Ahmad Mustafa Anis\source\repos\ciruclar queue\Source.cpp(8,8): error C2590: 'sig': only a constructor can have a base/member initializer list
1>Done building project "ciruclar queue.vcxproj" -- FAILED.
My code is
class CircularQueue {
public:
int dataItems[10];
sig() : dataItems{0, 0, 0, 0, 0, 0, 0, 0, 0, 0} { }
};
I have Visual Studio 2019, I guess c++ version in it is cpp17. If there is someway I can add a constructor and assign whole array to 0 without for loop or explicitly element by element, like this constructor
CircularQueue() {
dataItems = { 0 };
}
or this one
CircularQueue() {
dataItems = 0 ;
}
In both case my error is
error C3863: array type 'int [10]' is not assignable
sig()is not a Constructor. You can only use initializer lists with Constructors.