Ok, so this is related to my other question's project (Dice Game) here ( http://www.cplusplus.com/forum/beginner/117780/ ).
What I don't understand is I have:
* defined function prototypes, all in the fProtoType.hpp file
* declared functions, some distributed in iMessaging.cpp and others in iDiceFunct.cpp (diceFunct.cpp)
Yet, I run into the following output on build:
( Excrept )
1>playGame.obj : error LNK2019: unresolved external symbol "int __cdecl sumTotalDieLeft(int * const,int)"
(?sumTotalDieLeft@@YAHQAHH@Z) referenced in function "void __cdecl playGame(void)" (?playGame@@YAXXZ)
1>playGame.obj : error LNK2019: unresolved external symbol "class Dice __cdecl drawDice(int * const,int)"
(?drawDice@@YA?AVDice@@QAHH@Z) referenced in function "void __cdecl playGame(void)" (?playGame@@YAXXZ)
1>playGame.obj : error LNK2019: unresolved external symbol "int __cdecl rollDice(class Dice)"
(?rollDice@@YAHVDice@@@Z) referenced in function "void __cdecl playGame(void)" (?playGame@@YAXXZ)
1>N:\cPlusPlus\submoduleDieProb\Debug\submoduleDieProb.exe : fatal error LNK1120: 3 unresolved externals
I've tried cleaning up and rebuilding, but I have the feeling I'm forgetting some sort of "best practice" coding technique in my source somewhere...
iDieFunct.cpp (dieFunct.cpp)Excrept
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include "fProtoType.hpp"
[...] <- Some other code
int sumTotalDieLeft ( int totalUp[], int arraySize)
{
int accumulator = 0;
for ( int iElement = 0; iElement < arraySize; iElement++ )
{
accumulator += totalUp[iElement];
}
return accumulator;
}
fProtoType.hppExcrept
int sumTotalDieLeft( int[], int );
playGame.cppExcrept
1 2 3 4 5 6 7 8 9 10
#include "fProtoType.hpp"
playGame()
{
[...] <- Some other code
totalDieLeft = sumTotalDieLeft ( dieTypeIDLeft, DIE_TYPES );
}
By the way, I really appreciate the active responses from the community on the previous question. Glad you guys can take the time to show me a trick or two!
I don't understand why it is a problem. I've made the declaration and definition ( implementation ); I should be able to call it.
If the answer lies within templates, I'll be lost for a while. Most of what I've learned so far from C++ comes from either Starting Out With C++: Form Controls Through Objects, or StackOverflow...
I've noticed that all of the functions that get linker errors utilize other functions that are in the same translation unit. Perhaps by moving them outside to another T.U. will fix the problem.