|
What came first, the chicken or the pure virtual CAnimal?
|
|
|
|
|
Mattias Högström wrote: It is of course possible to apply the same principle in constructors by creating a virtual method called "Initialize" which you call from the constructor. When this method is redefined in a subclass it will override the parent's definition.
I don't think so.
http://www2.research.att.com/~bs/bs_faq2.html#vcall[^]
And even if it is now possible (or possible in other OO languages) it is something that should be used with a great deal of care. The reason for that is that because it is virtual then intent would be that it interacts both with the parent and child. And not understanding exactly how the parent and child are designed to work and not understanding in detail how the child parent are implemented can lead to problems. Especially when one considers maintenance.
And often when people want to do this it is because they do not understand the above or even understand what constructors are. So probably best to just say - don't do it.
|
|
|
|
|
you're right. I remember reading that before. It is unsafe or undefined to call a virtual method from the constructor. I was mearly trying to show the usage of virtual methods that can create objects by delegating the exact type to a subclass to define it. This is how some factories are implemented. But I should have stopped there. I went too far. Calling them from constructors are of course not possible due to how parents an children are created. I have never found any need for a virtual constructor, but virtual methods that create objects often.
|
|
|
|
|
Mattias Högström wrote: It is unsafe or undefined to call a virtual method from the constructor.
It is defined behavior.
Mattias Högström wrote: Calling them from constructors are of course not possible due to how parents an children are created
Not sure what that means. It not possible because the language definition doesn't allow it. Perhaps your reason is a restatement of why that rule exists.
|
|
|
|
|
jschell wrote:
It is defined behavior.
I suppose you mean that the defined behavior is that it isn´t allowed.
I meant that its behavior would be undefined if it was allowed.
jschell wrote: Not sure what that means. It not possible because the language definition doesn't allow it. Perhaps your reason is a restatement of why that rule exists.
Yes.
|
|
|
|
|
// Why there is no virtual constructor in C++? Can anybody explain me....
It would be a construction of a tool without its material :
- shaping of the hammer's hold, but without wood
- sharpening of the knife, but without steel
- ...
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
modified 17-Jul-12 6:20am.
|
|
|
|
|
By default (VC6), app icon is in 16 color only.
How to use/change the app icon with full color?
BTW: for VC6 environment.
Thanks.
.
|
|
|
|
|
After opening the icon in the icon editor, select New Image Type from the Image menu.
Here you can find all the color depths that are available.
If you do not see what you want, you can do one of the two.
Upgrade to a newer version of Visual Studio.
VS 2010 supports upto 32-bit icons.
Or you can edit the icon file using an external application like MS-Paint or Photoshop.
You do this after creating the icon from VC in the res sub-folder.
|
|
|
|
|
I am developing Dialog based application. It has "CListCtrl" list control and one "Editbox". My requirement is when user type in editbox, automatically the entered text should get selected in the list control.
For this,when i used "FindItem" , it always return -1 even the entered text available in list control.
Here my code
int nPointIndex = 0;
LVFINDINFO info;
int nIndex;
LPCTSTR lpszmyString;
info.flags = LVFI_PARTIAL|LVFI_STRING;
info.psz = _T("DFC102");
nPointIndex = m_cListCtrl.FindItem(&info,-1);
if( nPointIndex != LB_ERR )
{
m_cListCtrl.EnsureVisible(nPointIndex, FALSE);
m_cListCtrl.SetSelectionMark(nPointIndex);
m_cListCtrl.SetItemState(nPointIndex, LVIS_SELECTED | LVIS_FOCUSED, IDC_TAGBROWSER_LIST);
m_cListCtrl.RedrawItems(nPointIndex, nPointIndex);
m_cListCtrl.UpdateWindow();
}
|
|
|
|
|
Here is code that working for me :
LVFINDINFO FindInfo;
FindInfo.flags = LVFI_STRING | LVFI_PARTIAL;
FindInfo.psz = m_sItem; int nItem = m_List.FindItem(&FindInfo);
perhaps you try to search in subitems of the list ?
|
|
|
|
|
Yes you are correct. I am searching 2nd column how to solve. please help me.
|
|
|
|
|
I suggest you to use this[^] listcontrol, which can search in subitems (columns) too ...
modified 14-Jul-12 7:39am.
|
|
|
|
|
You could insert the column you want to search in first, and then change the display order afterwards so it becomes the second column. Or just implement your own search method:
CString token = "hello";
for(int i=0;i<GetItemCount();i++)
CString subitemvalue=GetItemText( i , 2);
if (subitemvalue == token)
return i;
}
|
|
|
|
|
What are the values held in your list control; i.e. is there one that starts with "DFC102"?
|
|
|
|
|
Hi Gurus,
Could you provide me some codes examples to use:
'fopen_s' and 'fscanf_s'.
Thanks
|
|
|
|
|
|
|
I got the following compile error message, for using:
srand(time(NULL));
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
Thanks
|
|
|
|
|
It's not an error, but a warning. Try:
srand((unsigned) time(NULL));
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
As already stated, it's not an error but a warning. Compiler is simply making sure you're doing it on purpose and not by mistake, remember that casting may lead to digits being dropped and rounding (hence the warning). Cast the data to the appropriate type and the compiler won't warn you about it anymore.
|
|
|
|
|
Hi,
I want to provide undo/redo drawing feature in MFC dialog based application. I am saving the images dynamically in a vector in OnMouseMove handler code. But when I am going to load the previous image on clicking Undo button, its getting distorted. the last image saved still remains there on the canvas. Can anybody tell me whats the issue with OnMouseMove handler. How the compiler will know when to end saving the image.?
Regards,
|
|
|
|
|
mbatra31 wrote: How the compiler will know when to end saving the image.?
The compiler knows nothing, it's your code that has to do the work. Without seeing some of your code it's impossible to know what is going on.
|
|
|
|
|
Don't save the image the "OnMouseMove" event handler, save it in the OnLButtonUp handler (normally when the action is finished); or else you will end up with thousands and thousands of images.
How are you saving and putting back the image ? BitBlt ? StretchBlt ? show us some code.
If the image is stretched, are you certain you are using the good Width and Height for the bitmap ?
Watched code never compiles.
|
|
|
|
|
Hi Maximilien,
Thanx for your response.
I have done that part. I am saving the images in OnLButtonUp event handler only.
Thanx & Regards,
|
|
|
|
|