I have recently moved from java to c++, so I'm not quite experienced with the use of pointers. I'm trying to translate a few of my old programs, and I have this problem:
I make a class (it stands for an ARMA time series), and I have a method wich modifies some of its variables. In other part of my program I have a function wich receives one object of this class as a parameter and, at some point, it calls the method of the ARMA class to modify it; here is my deal I want to pass the ARMA class
by reference to this function, because I want the variables of the instance I'm passing to be modified, not those of a copy the method uses. Also, I would like not to declare the function inside the class ARMA, cause I use it in other places too (it's basically a Nelder-Mead optimization what it performs).
Here is a code wich sketches what I've been trying, and exactly the error message I get is "modifyParameter has not been declared".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
#include <cstdlib>
using namespace std;
class ARMA{
private:
double parameter;
public:
void modifyParameter();
void printParameter();
ARMA(double);
};
void functionWichModifies(ARMA* arma); //For what I understood about pointers, here it says
//"This function will receive the direction of an
//ARMA object"
int main(){
ARMA myArma = ARMA(5);
myArma.printParameter();
functionWichModifies(&myArma); //So I pass the direction as an argument;
//So far, so good; I tried this exact code with an empty bodied
system("Pause"); //functionWichModifies (i.e. it does nothing) and no
//error appeared when compiling.
return 1;
}
ARMA::ARMA(double p){parameter = p;}
void ARMA::printParameter(){ cout << parameter << "\n";}
void ARMA::modifyParameter(){
parameter +=5;
}
void functionWichModifies(ARMA* arma){
*arma.modifyParameter(5); //Here is my problem: when I try the function to actually do something, I'm not quite sure
//about how doing It, since I'm trying to modify the original "myArma" object, I tried this
} //line, which I supossed it said "use the function modifyParameter in the object
//allocated in the direction *arma.
|
Thanks in advance, and I'm sorry if my questions turns up to be something really basic; I've read the documentation and still couldn`t figure out what's happening. Greets.