I am unable to figure out why exactly this error keeps occuring, I have tried adding libraries with no prevail.
error LNK2001: unresolved external symbol "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > Box::sAlphabet" (?sAlphabet@Box@@0V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A)
fatal error LNK1120: 1 unresolved externals
#include <iostream>
#include <string>
#include <iomanip>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <conio.h>
#include <windows.h>
#include <stdio.h>
using namespace std;
class Box
{
private:
int mX, mY, mSize, mColor, mDirection;
char mLetter[1];
static string sAlphabet;
public:
Box()
{
int alphaIdx;
mSize = 1 + rand() % 4;
mX = mSize + rand() % 76;
mY = mSize + rand() % 21;
do
{
alphaIdx = rand() % sAlphabet.length();
}while(sAlphabet[alphaIdx] == '*');
mLetter[0] = sAlphabet[alphaIdx];
sAlphabet[alphaIdx] = '*';
mColor = rand() % 14 + 1;
mDirection = rand() % 4;
}
void Display()
{
SetColor(mColor);
for(int x = mX; x < mSize + mX; x++)
for(int y = mY; y < mSize + mY; y++)
ConPrintAt(x, y, mLetter, 1);
}
// Program continues
The linker error is nothing to do with libraries. It's because you have declared but not defined your static member sAlphabet
Add the following at file scope.
string Box::sAlphabet;
Andy