Linker error

For some reason, there is an 'undefined refrence to 'calc_Fg()' according to the compiler. The variables are stored in a struct, and when I tested it by commenting out the function and using other ones, it worked fine. I can't seem to figure out what the problem is

1
2
3
4
5
6
7
8
9
10
void Fg(){
	cout <<"\n Mass of object 1 = ";
	cin >> vars.mass;
	cout << "\n Mass of object 2 = ";
	cin >> vars.mass2;
	cout <<"\n Distance between objects = ";
	cin >> vars.distance;
	vars.Fg = (6.674e-11)*((vars.mass*vars.mass2)/(vars.distance*vars.distance)); 
	cout << "\n Fg = " << vars.Fg << " Newtons.";
}


Any help is greatly appreciated.

Edit: *facepalm* Figured out the problem. I named the function 'Fg' instead of 'calc_Fg'. I can't believe I spent a week trying to figure out the problem...Thanks Computergeek01.
Last edited on
So... where is 'calc_Fg()'? That underscore is a legal character for a function name so if you're calling it like that then the definition has to be written as such. Try using 'ctrl+F' at your source file and try to find it.


EDIT: Problem, I see on line 8 that you have a member variable with the same name as your function? Is 'Fg()' a member function? If so then you need to first change the names so that they don't match, then you have to define it as a member function: in this case
1
2
3
4
void [DATA_TYPE]::Fg() 
{
   //...Your code
};


REEDIT: Please post your class definition.
Last edited on
No, it wasn't a member. Just naming the function wrong. It works now.

EDIT:
Heres the class definition if you're still interested.

1
2
3
4
5
6
7
8
9
struct Calculate_Me{  // basically a bunch of variable defs.
    public:
    complex<double> quadratic;
	double rad,deg,KE,momentum,impulse,force,work,power,quad_real,quad_imag,Fg,spring,Fe,frequency,wavelength,period; // calculated vars, split up to make it easier to program.
	double mass,accel,velocity,distance,p,time,mass2; // units to be used in calculations
	double vo,xo,po,to,wo,a,m,n,b,c; // initial values.
	int choice;
}vars;
// Yeah, I probably should combine all the 'double' variables into one massive line, but it makes it easier to see while writing the code, and having to scroll to the side bugs the hell out of me. 
Last edited on
Topic archived. No new replies allowed.