Write function definition header in .h file, and write function definition body in .cpp file.
How can I make linker know the definition body in the .cpp ?
I new a Win32 Application project, and I add .h and .cpp in "Header Files" and "Resource Files" folder, but it still couldn't find the definition body when Build...
"unresolved external symbol" errors typically mean you're trying to call a function which has a prototype, but no function body.
In this case, since you seem to have a function body in a .cpp file, make sure the function has the exact same name and exact same parameter list.
And in fact, if you want, you can post both the prototype (in the header) and the function definition (in the .cpp) so we can point out where the error is.
@OP, it looks like you are using VC++ so add the source for your functions into your project. That will link the source and implementation to your code.
And be sure to read Disch's article, it raises some important points about multi-dimensional arrays in C++.
# include<stddef.h>
# include<iostream.h>
template <class KeyType>
KeyType ***Allocate_3D( int z, int y, int x )
{
int i, j ;
KeyType ***f ;
f = (KeyType***) malloc( z * sizeof(KeyType**) ) ;
if(!f) return NULL ;
for ( i = 0 ; i < z ; i++ ) {
f[i] = (KeyType**) malloc( y * sizeof(KeyType*) ) ;
if(!f[i]) return NULL ;
for ( j = 0 ; j < y ; j++ ) {
f[i][j] = (KeyType*) malloc( x * sizeof(KeyType) ) ;
if(!f[i][j]) return NULL ;
} // for
} // for
return f ;
} // KeyType ***Allocate_3D( int z, int y, int x )
//-----------
Another question:
include<> is write in .h or .cpp ?
I write a function prototype void DeWhiteSpace( ifstream & inFile ) ; in "input.h",
and write a function body :
If I only write # include<fstream.h> once (in .h or .cpp), they also have compiler error.
But write the same include twice (in .h and .cpp), is standard writing ?