martinmoessner
asked on
Initializing a static member pointe
I did this ...
//CJATDoc.hpp
#include "SyntaxColorizer.h"
class CJATDoc : public CRichEditDoc
{
private:
static CSyntaxColorizer* m_sc;
...
}
//CJatDoc.cpp
CSyntaxColorizer CJATDoc::*m_sc = NULL;
CJATDoc::CJATDoc()
{
m_sc = new CSyntaxColorizer();
}
CJATDoc::~CJATDoc()
{
delete m_sc;
}
void CJATDoc::doComment()
{
...
m_sc->doColorizer();
...
}
Nevertheless I got the following linker error ...
ATDoc.obj : error LNK2001: Unresolved external symbol "private: static class CSyntaxColorizer * CJATDoc::m_sc" (?m_sc@CJATDoc@@0PAVCSynta xColorizer @@A)
Debug/JAT.exe : fatal error LNK1120: 1 unresolved external symbol
Any ideas ?
Martin
//CJATDoc.hpp
#include "SyntaxColorizer.h"
class CJATDoc : public CRichEditDoc
{
private:
static CSyntaxColorizer* m_sc;
...
}
//CJatDoc.cpp
CSyntaxColorizer CJATDoc::*m_sc = NULL;
CJATDoc::CJATDoc()
{
m_sc = new CSyntaxColorizer();
}
CJATDoc::~CJATDoc()
{
delete m_sc;
}
void CJATDoc::doComment()
{
...
m_sc->doColorizer();
...
}
Nevertheless I got the following linker error ...
ATDoc.obj : error LNK2001: Unresolved external symbol "private: static class CSyntaxColorizer * CJATDoc::m_sc" (?m_sc@CJATDoc@@0PAVCSynta
Debug/JAT.exe : fatal error LNK1120: 1 unresolved external symbol
Any ideas ?
Martin
CSyntaxColorizer* CJATDoc::m_sc = NULL;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is CJATDoc class inside of a namespace somehow?
corey
corey
corey,
Why would that be relevant?
Stefan
Why would that be relevant?
Stefan
insert the following sentence in your cpp file
CSyntaxColorizer* CJATDoc::m_sc = 0;
CSyntaxColorizer* CJATDoc::m_sc = 0;
Oh yea, obviously :)
You have a syntax error as rendaduiyan pointed out -- I just wanted to make that difference clear between your code and his.
I was wondering why my eyes wouldn't focus on that properly, too many symbols!
corey
You have a syntax error as rendaduiyan pointed out -- I just wanted to make that difference clear between your code and his.
I was wondering why my eyes wouldn't focus on that properly, too many symbols!
corey