Home>

There is a class:

template <
typename T >
class cFunctionVector {
public:
    cFunctionVector ()
    {
        functionsVector= new vector <
T >
();
    }
    cFunctionVector (vector <
T >
 _functionsVector)
    {
        functionsVector= _functionsVector;
    }
    void addFunction (T _function)
    {
        functionsVector.resize (functionsVector.size () + 1);
        functionsVector.push_back (_function);
    }
    int getAmount ()
    {
        return functionsVector.size ();
    }
    T getFunctionValue (int _number)
    {
        vector <
T >
:: iterator it= functionsVector.begin (); //problem line
        return * (it + _number);
    }
private:
    vector <
T >
 functionsVector;
};

The compiler swears at the marked line, error output:

need 'typename' before 'std :: vector <
T >
:: iterator 'because' std :: vector <
T >
'is a dependent scope

the method was written to get the i-th element of the fieldfunctionsVector, and the compiler swears, as I understand it, that the type (int,floatetc.), and there is a certain class T. But the fact of the matter is that a vector in this class can be of any type. How can you fix this? Or am I altogether wrongly trying to return the i-th element?

Why resize () before push_back ()? And in getFunctionValue you can just return functionsVector [_number];

avp2021-02-25 04:38:03

@ MorkOFF48, have you tried connecting and using the std :: function class? For some reason it seems to me that you have been reinventing the wheel for many days. Surely, the presence of such functionality would make you think about solving the problem itself, and not about what tools to solve it.

mega2021-02-25 04:38:03