
January 30th, 2004, 09:36 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
Function overloading just bit you there.
In C++, you can have several functions all with the exact same name but with different data types in the argument list. It's the different argument lists that makes each same-named function distinquishable from each other and allows the compiler to figure out which one you're calling. There's even a special term, "name mangling", that describes how the compiler appends the argument-list data types to the function name for the linker.
In test.h, you provide this function prototype:
double square (test &);
Yet in the other source file where you think that you're implementing that function, the function's header looks like this:
double square (test a)
You changed the argument-list data types, so it's a completely different function than you had prototyped in the header file. The linker error of "undefined reference to 'square(double &)'" is righteous because you never did implement a "square" function with a reference arguement (though I'm not sure why it's "double &" and not "test &").
You probably did intend the function's argument to be a reference, so just add the & and I think it should work.
|