I'm working on a program to take in an object with a name(string) and a number(double),put them into an array of objects, sort the objects by the number, and then output a list of names. When I try to output, though, it tells me "unresolved external symbol". I think it points to the output operator in the code below, but I'm not sure. Along that line of thought, I tried to overload the operator, but that only caused more problems and didn't seem to solve the original issue. Can anyone tell me where I'm going wrong? I put the function I think I'm having issues with, and the function that it calls, below.
Edit: Here are the error messages I'm getting:
Error LNK1120 1 unresolved externals Combat Sorter C:\Users\theog\OneDrive\The Gray System Work Stuff\Combat Sorter\Debug\Combat Sorter.exe 1
Error LNK2001 unresolved external symbol "class actor::Actor * aInitOrder" (?aInitOrder@@3PAVActor@actor@@A) Combat Sorter C:\Users\theog\OneDrive\The Gray System Work Stuff\Combat Sorter\Combat Sorter\Main.obj 1
Thank you for the help.
1 2 3 4 5 6 7 8 9 10 11 12 13
void printList(int iActorCount)
{
cout << "Here is the list of combatants: ";
for (int index = 0; index < iActorCount; index++)
{
aInitOrder[index].printName();
}
}
void Actor::printName()
{
cout << sActorName;
}
You need to post the complete error messages, all of them, exactly as they appear in your development environment. Those messages have important information embedded within them to aid in locating and fixing the problems.
Okay, now you will need to post the code for your classes, especially actor, both the definition and implementations. It would really be a good idea if you posted the smallest possible complete program that illustrates the problem.
#include "Actor.h"
#include <iostream>
#include <string>
usingnamespace std;
usingnamespace actor;
void makeList(int iActorCount);
void printList(int iActorCount);
int iActorCount = 0;
Actor aInitOrder[];
int main()
{
cout << "Enter the number of combatants: ";
cin >> iActorCount;
makeList(iActorCount);
printList(iActorCount);
system("PAUSE");
return 0;
}
void makeList(int iActorCount)
{
string sName;
double dRoll;
cout << "Enter the name and roll of the combatabt: ";
for (int index = 0; index < iActorCount; index++)
{
getline(cin, sName);
cin >> dRoll;
aInitOrder[index] = Actor(sName, dRoll);
}
}
void printList(int iActorCount)
{
cout << "Here is the list of combatants: ";
for (int index = 0; index < iActorCount; index++)
{
aInitOrder[index].printName();
}
}
TheIdeasMan, thank you for the recommendation. It got rid of the "unknown external symbol" error, but gave me this error instead.
1 2 3 4 5 6 7 8
public:
_Ty& operator[](const size_type _Pos)
{ // subscript mutable sequence
#if _ITERATOR_DEBUG_LEVEL == 2
if (size() <= _Pos)
{ // report error
_DEBUG_ERROR("vector subscript out of range");
}
I think that one came from the vector library, and it came up in "void makeList()" after I input the double value. I can't tell if it is because of the Actor constructor, the loop cycle, or some other issue.