my code is:
#pragma once
#include "stdafx.h"
#include <vector>
#include "field.h"
class output
{
void putAtLocation(COORD, char chIcon); //currently this outputs to console
static std::vector<COORD> m_vsOutputBuffer;
public:
output(void);
static void addToken(COORD);
void drawTokens();
~output(void);
};
and the linker error is:
output.obj : error LNK2001: unresolved external symbol "private: static class std::vector<struct _COORD,class std::allocator<struct _COORD> > output::m_vsOutputBuffer" (?m_vsOutputBuffer@output@@0V?$vector@U_COORD@@V?$allocator@U_COORD@@@std@@@std@@A)
this must be the problem line:
static std::vector<COORD> m_vsOutputBuffer;
I’ve been at this for hours stuck. I finally noticed that changing I’ve read that it’s(linker errors) are usually caused by dependency issues. COORD to int causes the linker error to go away.But here it just changing a I’ve also read it can be caused by using a function in a way it wasn’t supposed to be. I figure it has to be the way is handling TYPE.COORDs; or something about COORDS is forward declared, or referenced in output.cpp properly.
Edit:
all changing to int did was make compiler errors that caused it never to hit the linker. now I am back to nothing
and the cpp file:
#include "stdafx.h"
#include "output.h"
#include <vector>
static std::vector<int> m_vsOutputBuffer;
output::output(void)
{
}
void output::addToken(COORD sCoordinate) //mark a coord in the buffer as needing refreshed
{
m_vsOutputBuffer.push_back(sCoordinate);
}
void output::drawTokens() //release the outputbuffer the the output window
{
for (unsigned int iii = 0; iii < m_vsOutputBuffer.size(); iii++)
{
putAtLocation(m_vsOutputBuffer[iii], field::checkHit( m_vsOutputBuffer[iii] ) );
}
}
void output::putAtLocation(COORD sCoordinate, char chIcon) //outputs a single character to the console
{
DWORD dwNumWritten = 0;
LPDWORD lpdNumWritten = &dwNumWritten;
WriteConsoleOutputCharacter(
GetStdHandle( STD_OUTPUT_HANDLE ), //***repeatedly getting this handle may end up a bottleneck
LPCTSTR(&chIcon),
1,
sCoordinate,
lpdNumWritten
);
}
output::~output(void)
{
}
also I found this: http://www.cplusplus.com/forum/general/6111/
so I tried moving the static statement to the cpp file and it compiled and ran. but not its not a member variable. So I Need to somehow forward declare the vector.(before the declaration was also creating the static object in the header file.
you need this line in your
.cppfile:(Note the absence of
staticand the scopeoutput::)This is the actual definition of the member variable. What you have in the class (
.h) is only the declaration.Without this the static variable
output:m_vsOutputBufferdoes not exist and the linker rightfully complains that it can’t find it.