Click here to Skip to main content
15,904,935 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Multiple thread pool Pin
Mark Salsbery19-Nov-07 6:55
Mark Salsbery19-Nov-07 6:55 
AnswerRe: Multiple thread pool Pin
Mark Salsbery19-Nov-07 7:05
Mark Salsbery19-Nov-07 7:05 
QuestionAdd Menu Dynamically Pin
paresh_joe18-Nov-07 23:01
paresh_joe18-Nov-07 23:01 
AnswerRe: Add Menu Dynamically Pin
Hamid_RT18-Nov-07 23:16
Hamid_RT18-Nov-07 23:16 
QuestionOpen a word file from a web folder Pin
arslanjatt18-Nov-07 22:46
arslanjatt18-Nov-07 22:46 
AnswerRe: Open a word file from a web folder Pin
Jhony george18-Nov-07 23:29
Jhony george18-Nov-07 23:29 
GeneralRe: Open a word file from a web folder Pin
arslanjatt18-Nov-07 23:34
arslanjatt18-Nov-07 23:34 
Questionan link error Pin
richardye18-Nov-07 22:38
richardye18-Nov-07 22:38 
I write a program to count the number of objects. But when I compile it, I met with link errors. How can I resolve it?

Head files:

template <class beingcounted="">
class Counted
{
public:
class TooManyObjects{};
static int getObjectNum()
{
return m_ObjectNum;
};
protected:
Counted();
Counted(const Counted& count);
~Counted() { --m_ObjectNum; };
private:
static int m_ObjectNum;
static const size_t m_MaxObjectNum;
void init();
};

int Counted<class beingcounted="">::m_ObjectNum = 0;
const size_t Counted<class beingcounted="">::m_MaxObjectNum = 5;

class Printer: private Counted<printer>
{
public:
static Printer* makePrinter();
static Printer* makePrinter(const Printer& rhs);
~Printer();
void reset();
void performSelfTest();
using Counted<printer>::getObjectNum;
using Counted<printer>::TooManyObjects;
private:
Printer();
Printer(const Printer& rhs);
};

in definition file:

template <class beingcounted=""> Counted<beingcounted>::Counted()
{
init();
}

template <class beingcounted=""> Counted<beingcounted>::Counted(const Counted& count)
{
init();
}

template <class beingcounted=""> Counted<beingcounted>::init()
{
if(m_ObjectNum > m_MaxObjectNum)
{
throw TooManyObjects();
}
++m_ObjectNum;
}

Printer::Printer(){}
Printer::Printer(const Printer &rhs) {}
Printer::~Printer() {}

Printer* Printer::makePrinter()
{
return new Printer();
}

Printer* Printer::makePrinter(const Printer& rhs)
{
return new Printer(rhs);
}

error LNK2001 private static int Counted<class printer="">::m_ObjectNum"XXX" is unresloved
error LNK2019 protected: _thiscall Counted<class printer="">::Counted<class printer="">(void)
"private _thiscall Printer::Printer(void)"

why? Does the static memeber of a class can only be initialized by its base class. How about its derived class?
Many thanks
AnswerRe: an link error Pin
baerten18-Nov-07 23:14
baerten18-Nov-07 23:14 
GeneralRe: an link error Pin
CPallini18-Nov-07 23:22
mveCPallini18-Nov-07 23:22 
AnswerRe: an link error [modified] Pin
CPallini18-Nov-07 23:15
mveCPallini18-Nov-07 23:15 
GeneralRe: an link error Pin
toxcct18-Nov-07 23:18
toxcct18-Nov-07 23:18 
GeneralRe: an link error Pin
CPallini18-Nov-07 23:30
mveCPallini18-Nov-07 23:30 
QuestionA Question about API related to Registry Pin
Mushtaque Nizamani18-Nov-07 22:29
Mushtaque Nizamani18-Nov-07 22:29 
AnswerRe: A Question about API related to Registry Pin
Jhony george18-Nov-07 23:23
Jhony george18-Nov-07 23:23 
AnswerRe: A Question about API related to Registry Pin
SnaKeBeD18-Nov-07 23:36
SnaKeBeD18-Nov-07 23:36 
GeneralRe: A Question about API related to Registry Pin
Mushtaque Nizamani19-Nov-07 0:45
Mushtaque Nizamani19-Nov-07 0:45 
AnswerRe: A Question about API related to Registry Pin
krmed19-Nov-07 0:45
krmed19-Nov-07 0:45 
GeneralRe: A Question about API related to Registry Pin
Mushtaque Nizamani19-Nov-07 0:47
Mushtaque Nizamani19-Nov-07 0:47 
GeneralRe: A Question about API related to Registry Pin
Hamid_RT10-Apr-08 7:23
Hamid_RT10-Apr-08 7:23 
QuestionHow to use SetSelectionMark() Pin
Max++18-Nov-07 22:19
Max++18-Nov-07 22:19 
AnswerRe: How to use SetSelectionMark() Pin
_AnsHUMAN_ 18-Nov-07 22:33
_AnsHUMAN_ 18-Nov-07 22:33 
GeneralRe: How to use SetSelectionMark() Pin
Max++18-Nov-07 22:40
Max++18-Nov-07 22:40 
GeneralRe: How to use SetSelectionMark() Pin
Peter Weyzen18-Nov-07 22:51
Peter Weyzen18-Nov-07 22:51 
GeneralRe: How to use SetSelectionMark() Pin
Max++18-Nov-07 23:03
Max++18-Nov-07 23:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.