a link error about template and construction
-
template 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(); }; template Counted::Counted() { init(); } template Counted::Counted(const Counted& count) { init(); } template Counted::init() { if(m_ObjectNum > m_MaxObjectNum) { throw TooManyObjects(); } ++m_ObjectNum; } class Printer: private Counted { public: static Printer* makePrinter(); static Printer* makePrinter(const Printer& rhs); ~Printer(); void reset(); void performSelfTest(); using Counted::getObjectNum; using Counted::TooManyObjects; private: Printer(); Printer(const Printer& rhs); }; int Counted::m_ObjectNum = 0; const size_t Counted::m_MaxObjectNum = 5; Printer::Printer() { } Printer::Printer(const Printer &rhs) { } Printer::~Printer() { } Printer* Printer::makePrinter() { return new Printer(); } when I compile it, an unresolved symbol "protected _thiscall":Counted:Counted(void)" are function "private: _thiscall Printer:Printer(void)" reference I don't know its meaning. How can I resolv it link error? Many thanks.
-
template 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(); }; template Counted::Counted() { init(); } template Counted::Counted(const Counted& count) { init(); } template Counted::init() { if(m_ObjectNum > m_MaxObjectNum) { throw TooManyObjects(); } ++m_ObjectNum; } class Printer: private Counted { public: static Printer* makePrinter(); static Printer* makePrinter(const Printer& rhs); ~Printer(); void reset(); void performSelfTest(); using Counted::getObjectNum; using Counted::TooManyObjects; private: Printer(); Printer(const Printer& rhs); }; int Counted::m_ObjectNum = 0; const size_t Counted::m_MaxObjectNum = 5; Printer::Printer() { } Printer::Printer(const Printer &rhs) { } Printer::~Printer() { } Printer* Printer::makePrinter() { return new Printer(); } when I compile it, an unresolved symbol "protected _thiscall":Counted:Counted(void)" are function "private: _thiscall Printer:Printer(void)" reference I don't know its meaning. How can I resolv it link error? Many thanks.
Your code is almost unreadable, see point 5 here[^]. You should also replace the < and > characters by the symbols that are just above the emoticons otherwise they will be eaten (and for template, that will be quite difficult to understand). And please, post the exact error message.
Cédric Moonen Software developer
Charting control [v1.2] -
template 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(); }; template Counted::Counted() { init(); } template Counted::Counted(const Counted& count) { init(); } template Counted::init() { if(m_ObjectNum > m_MaxObjectNum) { throw TooManyObjects(); } ++m_ObjectNum; } class Printer: private Counted { public: static Printer* makePrinter(); static Printer* makePrinter(const Printer& rhs); ~Printer(); void reset(); void performSelfTest(); using Counted::getObjectNum; using Counted::TooManyObjects; private: Printer(); Printer(const Printer& rhs); }; int Counted::m_ObjectNum = 0; const size_t Counted::m_MaxObjectNum = 5; Printer::Printer() { } Printer::Printer(const Printer &rhs) { } Printer::~Printer() { } Printer* Printer::makePrinter() { return new Printer(); } when I compile it, an unresolved symbol "protected _thiscall":Counted:Counted(void)" are function "private: _thiscall Printer:Printer(void)" reference I don't know its meaning. How can I resolv it link error? Many thanks.
Why did you not preview your post prior to submitting it? Had you done so, you would have noticed a lot of important code has been hidden (it's not actually removed). Modify your post and surround the code with <pre> tags, and use the < above the smileys instead of the actual < character. With one small change, your code compiled fine for me.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Why did you not preview your post prior to submitting it? Had you done so, you would have noticed a lot of important code has been hidden (it's not actually removed). Modify your post and surround the code with <pre> tags, and use the < above the smileys instead of the actual < character. With one small change, your code compiled fine for me.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
template 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(); }; template Counted::Counted() { init(); } template Counted::Counted(const Counted& count) { init(); } template Counted::init() { if(m_ObjectNum > m_MaxObjectNum) { throw TooManyObjects(); } ++m_ObjectNum; } class Printer: private Counted { public: static Printer* makePrinter(); static Printer* makePrinter(const Printer& rhs); ~Printer(); void reset(); void performSelfTest(); using Counted::getObjectNum; using Counted::TooManyObjects; private: Printer(); Printer(const Printer& rhs); }; int Counted::m_ObjectNum = 0; const size_t Counted::m_MaxObjectNum = 5; Printer::Printer() { } Printer::Printer(const Printer &rhs) { } Printer::~Printer() { } Printer* Printer::makePrinter() { return new Printer(); } error LNK2019 unresolved symbol
-
template 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(); }; template Counted::Counted() { init(); } template Counted::Counted(const Counted& count) { init(); } template Counted::init() { if(m_ObjectNum > m_MaxObjectNum) { throw TooManyObjects(); } ++m_ObjectNum; } class Printer: private Counted { public: static Printer* makePrinter(); static Printer* makePrinter(const Printer& rhs); ~Printer(); void reset(); void performSelfTest(); using Counted::getObjectNum; using Counted::TooManyObjects; private: Printer(); Printer(const Printer& rhs); }; int Counted::m_ObjectNum = 0; const size_t Counted::m_MaxObjectNum = 5; Printer::Printer() { } Printer::Printer(const Printer &rhs) { } Printer::~Printer() { } Printer* Printer::makePrinter() { return new Printer(); } error LNK2019 unresolved symbol
richardye wrote:
error LNK2019 unresolved symbol
Which means nothing out of context. My guess is the following line is in error:
template Counted::Counted(const Counted& count)
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne