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. protected constructor

protected constructor

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
8 Posts 4 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.
  • S Offline
    S Offline
    samira forooghi
    wrote on last edited by
    #1

    hi every one How can i create object of a class with protected constructor? i dont want drived it from base class. is it possible using friend class? Plz Help me

    E _ S 3 Replies Last reply
    0
    • S samira forooghi

      hi every one How can i create object of a class with protected constructor? i dont want drived it from base class. is it possible using friend class? Plz Help me

      E Offline
      E Offline
      Eytukan
      wrote on last edited by
      #2

      Yes.

      Eg:
      class base
      {
      protected :
      base()
      {
      }
      friend ami;
      };

      class ami
      {
      public:
      base obj;
      };

      OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus

      S 1 Reply Last reply
      0
      • S samira forooghi

        hi every one How can i create object of a class with protected constructor? i dont want drived it from base class. is it possible using friend class? Plz Help me

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        A public static method in the class can be used to create the object of the class. The caller can then use the static method to create an object of the class.

        «_Superman_» I love work. It gives me something to do between weekends.

        S 1 Reply Last reply
        0
        • E Eytukan

          Yes.

          Eg:
          class base
          {
          protected :
          base()
          {
          }
          friend ami;
          };

          class ami
          {
          public:
          base obj;
          };

          OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus

          S Offline
          S Offline
          samira forooghi
          wrote on last edited by
          #4

          i test it but i get this error: error C2248: 'CAsynlstn::CAsynlstn' : cannot access private member declared in class 'CAsynlstn' [path]: see declaration of 'CAsynlstn::CAsynlstn'

          class CMyCtrl : public COleControl
          {

          private:
          friend class CAsynlstn;
          CMyCtrl();
          ~CMyCtrl();
          }

          //////////////////////////////////////////
          class CAsynlstn : public CAsyncSocket
          {

          private:
          CAsynlstn(COleControl* pDlg);
          virtual ~CAsynlstn();

          };
          ///////////////////////////////////////
          //CMyCtrl.h
          ///////////////////////////////////////
          public:
          CAsynSvSk* m_pSrvrSock;
          ///////////////////////////////////////
          //CMyCtrl.Cpp
          ///////////////////////////////////////

          m\_pLstnSock = new CAsynlstn(this) /\*error C2248: 'CAsynlstn::CAsynlstn' : cannot access private member declared in class 'CAsynlstn' \[path\]: see declaration of 'CAsynlstn::CAsynlstn'\*/
          
          E 1 Reply Last reply
          0
          • S samira forooghi

            i test it but i get this error: error C2248: 'CAsynlstn::CAsynlstn' : cannot access private member declared in class 'CAsynlstn' [path]: see declaration of 'CAsynlstn::CAsynlstn'

            class CMyCtrl : public COleControl
            {

            private:
            friend class CAsynlstn;
            CMyCtrl();
            ~CMyCtrl();
            }

            //////////////////////////////////////////
            class CAsynlstn : public CAsyncSocket
            {

            private:
            CAsynlstn(COleControl* pDlg);
            virtual ~CAsynlstn();

            };
            ///////////////////////////////////////
            //CMyCtrl.h
            ///////////////////////////////////////
            public:
            CAsynSvSk* m_pSrvrSock;
            ///////////////////////////////////////
            //CMyCtrl.Cpp
            ///////////////////////////////////////

            m\_pLstnSock = new CAsynlstn(this) /\*error C2248: 'CAsynlstn::CAsynlstn' : cannot access private member declared in class 'CAsynlstn' \[path\]: see declaration of 'CAsynlstn::CAsynlstn'\*/
            
            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #5

            class CAsynlstn : public CAsyncSocket
            {

            private:
            public:
            CAsynlstn(COleControl* pDlg);
            virtual ~CAsynlstn();

            }

            m_pLstnSock = new CAsynlstn(this); If you are creating object straight like this it has to be public. btw, what are you trying to do with this?

            He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

            1 Reply Last reply
            0
            • S samira forooghi

              hi every one How can i create object of a class with protected constructor? i dont want drived it from base class. is it possible using friend class? Plz Help me

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              Here's a solution from Mr C++ himself[^].

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              S 1 Reply Last reply
              0
              • _ _Superman_

                A public static method in the class can be used to create the object of the class. The caller can then use the static method to create an object of the class.

                «_Superman_» I love work. It gives me something to do between weekends.

                S Offline
                S Offline
                samira forooghi
                wrote on last edited by
                #7

                can you give me an example?

                1 Reply Last reply
                0
                • S Stuart Dootson

                  Here's a solution from Mr C++ himself[^].

                  Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                  S Offline
                  S Offline
                  samira forooghi
                  wrote on last edited by
                  #8

                  thanks Mr Stuart Dootson

                  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