#include <iostream>
usingnamespace std;
// function return values
enum {OK,FILTER_TOO_LONG};
// class to store properties of the Menu members
class Properties{
public:
double GetValues(int i) {return Values[i];} ;
void SetValues(int i, double NewValues[i]) { Values[i]=NewValues[i];};unsignedlong GetLength() {return Length;} ;
void SetLength(unsignedlong NewLength) { Length=NewLength;} ;
bool GetValid() {return Valid;} ;
bool SetValid(bool NewValid) { Valid=NewValid;} ;
double InitValues(unsignedlong Length) { Values = newdouble [Length];};
private:
double* Values; // the data values
unsignedlong Length; // number of data values
bool Valid; // true if the data values have been Valid by the user
};
class Menu{
public:
Menu();
~Menu();
private:
// define the filter and its initial values
Properties Filter;// = {0,0,false};
// define the original data and its initial values
Properties OriginalData;// = {0,0,false};
// define the filtered data and its initial values
Properties FilteredData;// = {0,0,false};
};
// Control the principal operations of the program
// Arguments: None
Menu::Menu()
{
Filter.SetLength(5);
}
int main()
{
}
I am using another class and I want to be able to access private members from this class. That is why I use accessors and mutators. One mutator function is causing me a lot of troubles.
void SetValues(int i, double NewValues[i]) { Values[i]=NewValues[i];};
When I compile it error pops out: error C2057: expected constant expression
The members should be private, so are there any solutions how to solve this problem and keep the functionality? I need to be able to access and change each element of the pointer Values using this mutator function.
Thank you for the help!
class A{
friendclass B; //B has access to private members of A
};
void Properties::SetValues(double NewValues[]); //change the entirely array (your class knows the size)
void Properties::SetValues(int index, double NewValue); //change one value
However your setter/getter don't do anything. It's the same as having the members public.
Edit: SetLength is too dangerous, and InitValues could cause memory leaks. Why don't just use a std::vector?