Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. a link error about template and construction

a link error about template and construction

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    richardye
    wrote on last edited by
    #1

    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.

    C D 2 Replies Last reply
    0
    • R richardye

      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.

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      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]

      1 Reply Last reply
      0
      • R richardye

        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.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        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

        R 1 Reply Last reply
        0
        • D David Crow

          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

          R Offline
          R Offline
          richardye
          wrote on last edited by
          #4

          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

          D 1 Reply Last reply
          0
          • R richardye

            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

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups