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. Managed C++/CLI
  4. How can I prevent a class from being inherited

How can I prevent a class from being inherited

Scheduled Pinned Locked Moved Managed C++/CLI
questionhelptutorial
6 Posts 2 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

    How can I prevent a class from being inherited? My idea is to declare the constructor of the base class to be prviate. Is it correct? For example class A { private: A() {}; public: ~A() {}; } class B : public A { public: B() {}; ~B() {}; } int main() { B b; return 0; } As I compile the program, error C2248 happen. Is it all right? Is there any good idea of preventing a class from being inherited? many thanks.

    G 1 Reply Last reply
    0
    • R richardye

      How can I prevent a class from being inherited? My idea is to declare the constructor of the base class to be prviate. Is it correct? For example class A { private: A() {}; public: ~A() {}; } class B : public A { public: B() {}; ~B() {}; } int main() { B b; return 0; } As I compile the program, error C2248 happen. Is it all right? Is there any good idea of preventing a class from being inherited? many thanks.

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      Have a look at sealed keyword.

      #region signature my articles #endregion

      R 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        Have a look at sealed keyword.

        #region signature my articles #endregion

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

        Excuse me, I can't find any subjects I want in your articles. Can you give me a link to it or say in more details? thanks.

        G 1 Reply Last reply
        0
        • R richardye

          Excuse me, I can't find any subjects I want in your articles. Can you give me a link to it or say in more details? thanks.

          G Offline
          G Offline
          Giorgi Dalakishvili
          wrote on last edited by
          #4

          I didn't mean my articles, it's just my signature. Just look up sealed keyword.

          #region signature my articles #endregion

          R 1 Reply Last reply
          0
          • G Giorgi Dalakishvili

            I didn't mean my articles, it's just my signature. Just look up sealed keyword.

            #region signature my articles #endregion

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

            oh, I see. I have found the topic through keyword research. Thank you very much indeed.

            G 1 Reply Last reply
            0
            • R richardye

              oh, I see. I have found the topic through keyword research. Thank you very much indeed.

              G Offline
              G Offline
              Giorgi Dalakishvili
              wrote on last edited by
              #6

              You are welcome :)

              #region signature my articles #endregion

              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