I am attempting to change a value in a vector which is a variable in a class using a function of a class. When I compile, i get the following errors pointing to the “check[c] = cval;” line:
-
error C3867: ‘acc::check’: function call missing argument list; use ‘&acc::check’ to create a pointer to member
-
error C2109: subscript requires array or pointer type
Note: I have already initialized C to be 0 elsewhere in the program. It might be throwing an error because I am giving the address a variable instead of an integer, but when I substitute the variable with an integer, I still get the same errors.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;
class acc
{
public:
void add_Cval(double cval);
private:
vector<double> check(); //vector of all checks
int c; //loop marker for cvals
};
void acc::add_Cval(double cval)
{
check[c] = cval;
c++;
}
checkis a method, not a data member, so you need to invoke it –check().or make it a data member: