Help with no default constructor message
-
Not home now Dr appt but I'll paste the entire output in about 1 and 1/2 thanks so so so much
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)
-
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)
I'm glad you got it fixed. :)
The difficult we do right away... ...the impossible takes slightly longer.
-
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.
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
-
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
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.
-
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.
-
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
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.
-
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.
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
-
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
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 forptr
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.
-
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 forptr
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.
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
-
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.
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
-
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
A common solution to add such functionality is adding a
KeyStroke
member to your Rich Edit derived class and pass thethis
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). -
A common solution to add such functionality is adding a
KeyStroke
member to your Rich Edit derived class and pass thethis
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).