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. Help with no default constructor message

Help with no default constructor message

Scheduled Pinned Locked Moved C / C++ / MFC
help
19 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.
  • L Lost User

    Sorry, I cannot make head or tail of that. Can you show the class definition for Keystroke and indicate exactly where the error message occurs?

    F Offline
    F Offline
    ForNow
    wrote on last edited by
    #5

    Not home now Dr appt but I'll paste the entire output in about 1 and 1/2 thanks so so so much

    F 1 Reply Last reply
    0
    • F ForNow

      I did that I am still getting errors as stated below

      \progedit.cpp(13): error C2062: type 'int' unexpected

      1> progdialog.cpp

      while intellsense says class KeyStroke "KeyStroke" is a nonstatic data member or base class of class Cprogedit I have KeyStroke in Cprogedit.h as KeyStroke mystroke; in the public section of the class I have defined a constructor for Cprogedit which will provide the paramters for Keystroke as such

      CProgedit::CProgedit(int numlines, CProgedit* editptr) : KeyStroke(int numlines, CProgedit* editptr)

      KeyStroke::KeyStroke()
      {
      }
      KeyStroke::KeyStroke(int numlines, CRichEditCtrl* editptr)
      {
      max_line = numlines;
      edit_ptr = editptr;
      }

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #6

      ForNow wrote:

      CProgedit::CProgedit(int numlines, CProgedit* editptr) : KeyStroke(int numlines, CProgedit* editptr)

      This is a problem. While you're declaring the CProgedit constructor on the left-hand side, the part on the right-hand side is actually a call, so you wouldn't put the data types of the aguments. In other words, try the following:

      CProgedit::CProgedit(int numlines, CProgedit* editptr) : KeyStroke(numlines, editptr)

      Let me know if this helps.

      The difficult we do right away... ...the impossible takes slightly longer.

      F 2 Replies Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        ForNow wrote:

        CProgedit::CProgedit(int numlines, CProgedit* editptr) : KeyStroke(int numlines, CProgedit* editptr)

        This is a problem. While you're declaring the CProgedit constructor on the left-hand side, the part on the right-hand side is actually a call, so you wouldn't put the data types of the aguments. In other words, try the following:

        CProgedit::CProgedit(int numlines, CProgedit* editptr) : KeyStroke(numlines, editptr)

        Let me know if this helps.

        The difficult we do right away... ...the impossible takes slightly longer.

        F Offline
        F Offline
        ForNow
        wrote on last edited by
        #7

        Richard Thanks :) almost I got a compiler error saying KeyStroke not a member ... and that's right KeyStroke was a type as I declared KeyStroke mykey. However when I declared I got a clean build

        CProgedit::CProgedit(int numlines, CProgedit* editptr) : mykey(numlines, editptr)

        Richard Andrew x64R 1 Reply Last reply
        0
        • F ForNow

          Not home now Dr appt but I'll paste the entire output in about 1 and 1/2 thanks so so so much

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #8

          Richard, Richard Andrew X64 got me pointed in the right direction For the Class Declaration KeyStroke mykeys; inside class Cprogedit : public CrichEditctrl this was the necessary constructer

          CProgedit::CProgedit(int numlines, CProgedit* editptr) : mykeys(numlines, editptr)

          1 Reply Last reply
          0
          • F ForNow

            Richard Thanks :) almost I got a compiler error saying KeyStroke not a member ... and that's right KeyStroke was a type as I declared KeyStroke mykey. However when I declared I got a clean build

            CProgedit::CProgedit(int numlines, CProgedit* editptr) : mykey(numlines, editptr)

            Richard Andrew x64R Offline
            Richard Andrew x64R Offline
            Richard Andrew x64
            wrote on last edited by
            #9

            I'm glad you got it fixed. :)

            The difficult we do right away... ...the impossible takes slightly longer.

            1 Reply Last reply
            0
            • Richard Andrew x64R Richard Andrew x64

              ForNow wrote:

              CProgedit::CProgedit(int numlines, CProgedit* editptr) : KeyStroke(int numlines, CProgedit* editptr)

              This is a problem. While you're declaring the CProgedit constructor on the left-hand side, the part on the right-hand side is actually a call, so you wouldn't put the data types of the aguments. In other words, try the following:

              CProgedit::CProgedit(int numlines, CProgedit* editptr) : KeyStroke(numlines, editptr)

              Let me know if this helps.

              The difficult we do right away... ...the impossible takes slightly longer.

              F Offline
              F Offline
              ForNow
              wrote on last edited by
              #10

              KeyStroke mykey; defined in Cprogedit.h

              CProgedit::CProgedit(int numlines, CProgedit* editptr) : mykey(numlines, editptr)

              KeyStroke::KeyStroke(int numlines, CRichEditCtrl* editptr)

              Cprogedit* myrich = new Cprogedit((int) 30, myrich); DO you think this will work. What I mean is the two parameters are being passed to KeyStroke but will myrich have a vaule before KeyStroke constructor is called

              Richard Andrew x64R 1 Reply Last reply
              0
              • F ForNow

                KeyStroke mykey; defined in Cprogedit.h

                CProgedit::CProgedit(int numlines, CProgedit* editptr) : mykey(numlines, editptr)

                KeyStroke::KeyStroke(int numlines, CRichEditCtrl* editptr)

                Cprogedit* myrich = new Cprogedit((int) 30, myrich); DO you think this will work. What I mean is the two parameters are being passed to KeyStroke but will myrich have a vaule before KeyStroke constructor is called

                Richard Andrew x64R Offline
                Richard Andrew x64R Offline
                Richard Andrew x64
                wrote on last edited by
                #11

                I think that will definitely not work. Because it passes an uninitialized value into the constructor before it returns the new pointer. ;)

                The difficult we do right away... ...the impossible takes slightly longer.

                F 2 Replies Last reply
                0
                • Richard Andrew x64R Richard Andrew x64

                  I think that will definitely not work. Because it passes an uninitialized value into the constructor before it returns the new pointer. ;)

                  The difficult we do right away... ...the impossible takes slightly longer.

                  F Offline
                  F Offline
                  ForNow
                  wrote on last edited by
                  #12

                  Is there any way this is do-able What I mean by that is I am sure you know MFC internals better than me does get the storage for the Object class BEFORE it calls one or all of the member classes/object in the class For some reason I thought that it did

                  Richard Andrew x64R 1 Reply Last reply
                  0
                  • F ForNow

                    Is there any way this is do-able What I mean by that is I am sure you know MFC internals better than me does get the storage for the Object class BEFORE it calls one or all of the member classes/object in the class For some reason I thought that it did

                    Richard Andrew x64R Offline
                    Richard Andrew x64R Offline
                    Richard Andrew x64
                    wrote on last edited by
                    #13

                    I don't know what to tell you because you need to explain what you are trying to accomplish. If we can talk about what you want to accomplish, then we can probably find a solution. Why do you think you need to do it this way?

                    The difficult we do right away... ...the impossible takes slightly longer.

                    F 1 Reply Last reply
                    0
                    • Richard Andrew x64R Richard Andrew x64

                      I don't know what to tell you because you need to explain what you are trying to accomplish. If we can talk about what you want to accomplish, then we can probably find a solution. Why do you think you need to do it this way?

                      The difficult we do right away... ...the impossible takes slightly longer.

                      F Offline
                      F Offline
                      ForNow
                      wrote on last edited by
                      #14

                      I wrote a number of rich edit classes after finishing I realized they would all have common functionality 1) processing KeyStrokes 2) cursor select 3) Finding data I decided to encompass all of this in a class called KeyStroke which would expand functioality on a EditCtrl object so I declared KeyStroke mykey1; etc; 2 3 ... The constructor of KeyStroke takes a RicheditObject it was my understanding that when "new" build a class/object the First thing it does is allocate storage for the class/object and then call member classes which is why I thought this was doable Thanks

                      Richard Andrew x64R 1 Reply Last reply
                      0
                      • F ForNow

                        I wrote a number of rich edit classes after finishing I realized they would all have common functionality 1) processing KeyStrokes 2) cursor select 3) Finding data I decided to encompass all of this in a class called KeyStroke which would expand functioality on a EditCtrl object so I declared KeyStroke mykey1; etc; 2 3 ... The constructor of KeyStroke takes a RicheditObject it was my understanding that when "new" build a class/object the First thing it does is allocate storage for the class/object and then call member classes which is why I thought this was doable Thanks

                        Richard Andrew x64R Offline
                        Richard Andrew x64R Offline
                        Richard Andrew x64
                        wrote on last edited by
                        #15

                        If you do,

                        CObject* ptr = new CObject();

                        It performs that in two steps: 1. Calls the CObject constructor 2. Then it assigns the instance to the ptr ptr is uninititalized when the CObject constructor is called. It's not initialized until after the constructor returns. It might allocate the memory for ptr before it calls the constructor, but it does not contain a useful value. It's uninitialized until the assignment occurs.

                        The difficult we do right away... ...the impossible takes slightly longer.

                        F 1 Reply Last reply
                        0
                        • Richard Andrew x64R Richard Andrew x64

                          If you do,

                          CObject* ptr = new CObject();

                          It performs that in two steps: 1. Calls the CObject constructor 2. Then it assigns the instance to the ptr ptr is uninititalized when the CObject constructor is called. It's not initialized until after the constructor returns. It might allocate the memory for ptr before it calls the constructor, but it does not contain a useful value. It's uninitialized until the assignment occurs.

                          The difficult we do right away... ...the impossible takes slightly longer.

                          F Offline
                          F Offline
                          ForNow
                          wrote on last edited by
                          #16

                          Thanks I think the only other way I Might ? be able to do what I want is use the "this" pointer Assuming that KeyStroke is a Abstract Object used within the context of Cricheditctrl The this pointer would be that of the CRicheditctrl I can set a breakpoint inside the KeyStroke constructer check the "this" value and check "myrich =" pointer afterwards to see if they are the same value otherwise I guess I would set the richedit ptr after I allocate the object thanks

                          1 Reply Last reply
                          0
                          • Richard Andrew x64R Richard Andrew x64

                            I think that will definitely not work. Because it passes an uninitialized value into the constructor before it returns the new pointer. ;)

                            The difficult we do right away... ...the impossible takes slightly longer.

                            F Offline
                            F Offline
                            ForNow
                            wrote on last edited by
                            #17

                            In the KeyStroke Contructor I cast a "this" pointer to CRicheditctrl * and I wrote down the address I then observed Cricheditctrl pointer assigned after the new and it was the same address i'll cut and paste the code for more clarity

                            KeyStroke::KeyStroke(int numlines, CRichEditCtrl* editptr)
                            {
                            max_line = numlines;
                            edit_ptr = editptr;
                            edit_ptr = (CRichEditCtrl*)this;
                            }

                            myedit = new CProgedit((int)30,myedit); // allocate the richedit

                            1 Reply Last reply
                            0
                            • F ForNow

                              Hi I have a number of rich edit classes in my project. Defined basically as such class Myrich : public CrichEditCtrl they all have a default constructor with no parameters I now wanted to extend their functionality with paging (up or down) cursor selection etc. So I wrote a class KeyStroke. I declared KyStroke(s) in each of my classes as such KeyStroke mykeys; in my .h class definitions. My constructer for KeyStroke takes 2 parameters the number of lines in the rich edit and a pointer to a rich edit class So that meant I would have to modify my rich edit constructor as such MyRich::MyRich() ---> MyRich::MyRich(int numlines, CRichEditCtrl* myrichptr) : KeyStroke(int numlines, CRichEditCtrl* myrichptr) I am getting all sorts of errors with this such as "int" unexpected and KeyStroke no default contsructor

                              J Offline
                              J Offline
                              Jochen Arndt
                              wrote on last edited by
                              #18

                              A common solution to add such functionality is adding a KeyStroke member to your Rich Edit derived class and pass the this pointer to the member:

                              class MyRich public CRichEditCtrl
                              {
                              public:
                              MyRichyRich(int numlines);
                              KeyStroke m_KeyStroke;
                              };

                              MyRich::MyRich(int numlines) :
                              m_KeyStroke(numlines, this)
                              {
                              }

                              But this will generate a C4355 warning. To avoid that, you can make the KeyStroke member a pointer and allocate it in the constructor:

                              MyRich::MyRich(int numlines)
                              {
                              m_pKeyStroke = new KeyStroke(numlines, this);
                              }

                              or provide an initialisation function:

                              MyRich::MyRich(int numlines)
                              {
                              m_KeyStroke.Init(numlines, this);
                              }

                              Your problem is not the error message from the subject but that you want to access your Rich Edit object before it is created (and did not use this instead).

                              F 1 Reply Last reply
                              0
                              • J Jochen Arndt

                                A common solution to add such functionality is adding a KeyStroke member to your Rich Edit derived class and pass the this pointer to the member:

                                class MyRich public CRichEditCtrl
                                {
                                public:
                                MyRichyRich(int numlines);
                                KeyStroke m_KeyStroke;
                                };

                                MyRich::MyRich(int numlines) :
                                m_KeyStroke(numlines, this)
                                {
                                }

                                But this will generate a C4355 warning. To avoid that, you can make the KeyStroke member a pointer and allocate it in the constructor:

                                MyRich::MyRich(int numlines)
                                {
                                m_pKeyStroke = new KeyStroke(numlines, this);
                                }

                                or provide an initialisation function:

                                MyRich::MyRich(int numlines)
                                {
                                m_KeyStroke.Init(numlines, this);
                                }

                                Your problem is not the error message from the subject but that you want to access your Rich Edit object before it is created (and did not use this instead).

                                F Offline
                                F Offline
                                ForNow
                                wrote on last edited by
                                #19

                                Thanks upon entry to the constructer the "this" pointer is valid Thanks

                                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