Hi folks,
I learned a great deal today from experts on this board; hopefully I'll meet those kind people again...
Anyway, here's my program, spanning in three files whereas I am not sure how to properly use extern keyworld.
The main() file:
The file "function.h":Code:#include <cstdlib> #include <iostream> #include "function.h" using namespace std; double f(double x) { return g(x, array1, A); } int main() {const int A=5; double array1[A]; double x; for (int i=0;i<A;i++) array1[i]=i; x=3.4; cout<<"The f(3.4) is: "<<f(x)<<endl; system("PAUSE"); return EXIT_SUCCESS; }
The file "gfunction.cpp" that defines the g(.) function:Code:extern const int A; extern double *array1; //declare the function g(.) double g(double x, double *array, int arraydim);
whereas the error message is:Code:#include <cmath> #include "function.h" double g(double x, double *array, int arraydim) { double value=0; for (int i=0;i<arraydim;i++) { value=value+pow(array[i],i)+pow(x,2.0); } return value; }
What's wrong with my use of extern variables? My working environment is Bloodshed Dev C++ (it's so good; I love it!)Code:[Linker error] undefined reference to `A' [Linker error] undefined reference to `array1' ld returned 1 exit status
Thanks a lot...



LinkBack URL
About LinkBacks



CornedBee