class stepfunction: public FunzioneBase {
public:
stepfunction(double step, double intervallo);
~stepfunction();
void SetN(int n) {_n = n;} //this value of n concerns the output of Eval virtual function
virtualdouble Eval(double x) const;
protected:
double _step;
double _intervallo;
int _n;
};
#endif
Ok, no problem here.
What I'm struggling on is the correct syntax in order to call my void function SetN(int n) in this specific situation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int main() { //portion of main.cpp
FunzioneBase* f = new stepfunction(1, 1);
Integral* s = new Integral(-2, 2, f);
double* c = newdouble[10];
for(int n = 1; n <= 10; n++) {
stepfunction->SetN(n); //HERE the problem. The compliator isn't that happy with such a call
c[n] = (0.5)*s->simpson(100000); //simpson is an integration method from Integral class. It calls Eval virtual function in its body too.
}
I actually get: " error: expected unqualified-id before '->' token".
I can't get it to work, I've tried several alternatives.
Can anyone point me out what I'm getting wrong? It would be really appreciated!
You also want to define all the virtual non-pure functions.
Side note: I think it's C#'s thing, from the .NET team, to put prefix underscores in front of private vars, but in C++ vars starting with underscores are actually reserved (e.g. _WIN32) . I'd put underscores as suffixes if you like to use them.
compiler error: C++0x auto only available with -std=c++0x or -std=gnu++0x
That tells that your compiler is GCC and a version that does have some C++11 features. The default language is C++03 with GNU extensions. The compiler option -std= can change that.
Current C++ is already C++17. You can most likely get a new version of GCC that has more up to date language support and you definitely should experiment with the -std=, for only the very latest versions of GCC do change the default from the (now ancient) C++03.
Furthermore, I'd recommend disabling the GNU extensions. They cause more confusion than benefit for a learner of C++.