|
thank you very much
But I think I'd better study the basic of c++ frist
I'v found what cause the prablem,but it is not what we discussed above.
thanks again
|
|
|
|
|
well you should still post what the problem was and how you solved it so that other members of CP can benefit from what you learned if they ever come across that same situation
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
Hello,
I have a strange problem with one of my classes. I have the following two classes:
<br />
template <class T0, class T1 ><br />
class SomeClass<br />
{<br />
public:<br />
typedef T0 Type0;<br />
<br />
SomeClass() {}<br />
virtual ~SomeClass() {}<br />
<br />
virtual bool DoFoo(Type0 Param1) = 0;<br />
virtual int DoFoo(Type0 Param1, int nParam2) { }<br />
<br />
};<br />
<br />
class OtherClass : public SomeClass<A, B><br />
{<br />
public:<br />
virtual bool DoFoo(Type0 nParam1) { }<br />
};<br />
And somewhere I have this code:
<br />
void SomeFunction()<br />
{<br />
OtherClass otherClass;<br />
<br />
otherClass.DoFoo(1);
otherClass.DoFoo(1, 1);
}<br />
My problem is that in SomeFunction the compiler issues C2660 for a completly valid function call. The compiler says that it doesn't know DoFoo(int, int) . I have no idea why this error is issued...
[EDIT]
I'm using VS 2005 if it is of any help.
[\EDIT]
Blog[^]
|
|
|
|
|
could be that the compiler gets confused with the A Type0 and T0.
why don^t you try casting...call it like:
otherClass.DoFoo( (Type0)1, 1);
I`m not sure that`ll solve your problem, but I`ve had similar probs..
Greets,
Davy
|
|
|
|
|
Hello,
That doesn't work. It shouldn't even matter, because the compiler says that it doesn't know that function with 2 parameters. It only knows the function with just one parameter.
If I add the function to the derived class, there is no problem..
Blog[^]
|
|
|
|
|
Bob Stanneveld wrote:
class OtherClass : public SomeClass<A, B>
What are A and B?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
A can be any non-class data type (a struct or any primitive type) and B is some policy class..
Blog[^]
|
|
|
|
|
The problem has nothing to do with templates. It's because OtherClass's DoFoo override hides the base class's DoFoo(Type0, int). Just adding
class OtherClass : public SomeClass<A, B>
{
public:
using SomeClass<int,int>::DoFoo;
virtual bool DoFoo(Type0 nParam1) { }
};
solves the problem. The using statement brings all DoFoo overloads of SomeClass into OtherClass's "namespace", so it works fine. This problem occurs whenever you have overloaded virtual methods in the base class and you're selectively overriding them in the derived class.
Caught me on the wrong foot too, I was suspecting template instantiation problems .
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hello,
I didn't know that if you override just one of many base class overloaded functions, all the base class overloads are hidden! Nice to know that this happens.
Thanks a lot
Blog[^]
|
|
|
|
|
I want to make a selection between Low Frecuency "LF_1" and High Frecuency "HF_1" with a radio button so i have to change te parameter of elTipo with it how can i do this because i try but it doesnt works
<br />
<br />
#include "include/Coordinador/CoordinadorFrecELAI.h"<br />
void CRespuestaenfrecuenciav001Dlg::OnCalcularBode() <br />
{<br />
UpdateData(true);<br />
<br />
CList<double,double> elModulo;<br />
CoordinadorFrecELAI elCoordinador;<br />
tipoFiltro elTipo = LF_1;<br />
<br />
elCoordinador.ponerCircuito(elTipo,m_Resistencia,m_Condensador);<br />
<br />
elCoordinador.ponerParamResFr(m_frInicio,m_frFinal,m_frIntervalo,elModulo);<br />
<br />
CString aux;<br />
m_Resultado= "";<br />
POSITION pos = elModulo.GetHeadPosition();<br />
for (int i=0;i<elModulo.GetCount();i++)<br />
{<br />
aux.Format("%f\r\n",elModulo.GetNext(pos));<br />
m_Resultado += aux;<br />
}<br />
UpdateData(false)<br />
}<br />
|
|
|
|
|
alvarillo wrote:
I want to make a selection between Low Frecuency "LF_1" and High Frecuency "HF_1" with a radio button...
The easiest way to deal with radio buttons is to assign each of them a CButton member variable. You can use ClassWizard to do this but only if each of the controls on the dialog's template has the WS_GROUP style. Once you've assigned all of the controls to a CButton member variable, remove the WS_GROUP style from all but the first control. See here for more.
Now it is simply a matter of calling the button's GetCheck() and SetCheck() methods. Using UpdateData() in this context is problematic.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi
I have a listbox on my dialog and some Add, Modify and Remove buttons. If I select an item in the listbox and click Remove, the item gets removed and the Remove button gets disabled (as no item is selected).
When I do this, the item gets removed correctly but now my focus is completely lost. Pressing Tab or Enter or Escape doesn't do anything. I can still use the mouse though.
I tried adding a m_pbtnAdd->SetFocus() to the OnBtnRemove function, but it makes no difference.
Does anyone know the proper way to remove an item from a listbox in this way?
Thanks
d3m0n
|
|
|
|
|
You'll need to post your code as I have several examples of doing this and it works fine.
Cheers,
Tom Archer - Archer Consulting Group
"So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe
|
|
|
|
|
Tom
Please tell me what I'm doing wrong.
Thanks
void CDlgListboxTest::OnBtnRemove()
{
int nSelectedItem = m_lbTest.GetCurSel();
if (nSelectedItem != LB_ERR)
m_lbTest.DeleteString(nSelectedItem);
UpdateControls();
}
void CDlgListboxTest::UpdateControls()
{
BOOL bEnable = FALSE;
int nSelectedItem = m_lbTest.GetCurSel();
if (nSelectedItem != LB_ERR)
bEnable = TRUE;
m_btnModify.EnableWindow(bEnable);
m_btnRemove.EnableWindow(bEnable);
}
|
|
|
|
|
I've got to go to a meeting with a client now, but if someone hasn't helped you by this evening, I'll see if I can.
Cheers,
Tom Archer - Archer Consulting Group
"So look up ahead at times to come, despair is not for us. We have a world and more to see, while this remains behind." - James N. Rowe
|
|
|
|
|
[d3m0n] wrote:
BOOL bEnable = FALSE; int nSelectedItem = m_lbTest.GetCurSel();
Here is the error! after Deleting the item from LIST,
The current selection of list is LB_ERR. So bEnable is always FALSE
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Thanks for the reply but I think you may have misunderstood.
After removing the item, the button SHOULD be disabled, because there is no item to remove (so I don't want the Remove button enabled).
My issue is that after I disable the button, the dialog has lost the focus and I cannot tab or cancel the dialog.
This problem is quite strange I think
Cheers
|
|
|
|
|
The problem isn't the bEnable state for the buttons but the focus of the list box, right?
If so, maybe this will help:
This code sets the selection to a new item (since the one that was previously selected was removed) and sets the focus on the list box/control:
LVITEM lvItem;<br />
::ZeroMemory(&lvItem,sizeof(LVITEM));<br />
lvItem.stateMask = LVIS_SELECTED;<br />
lvItem.mask = LVIF_STATE;<br />
lvItem.state = LVIS_SELECTED; <br />
m_TaskList.SetItemState(nItem,&lvItem);<br />
m_TaskList.SetFocus();
|
|
|
|
|
I whipped up a quick project and experienced the same thing.
It did work for me however if I set the focus to the add button prior to disable:
<br />
void CTestDlg::UpdateControls()<br />
{<br />
BOOL bEnable = FALSE;<br />
<br />
int nSelectedItem = m_listBox.GetCurSel();<br />
if (nSelectedItem != LB_ERR)<br />
bEnable = TRUE;<br />
<br />
if (!bEnable)<br />
m_btnAdd.SetFocus();<br />
<br />
<br />
m_btnModify.EnableWindow(bEnable);<br />
m_btnRemove.EnableWindow(bEnable);<br />
}<br />
I also tried using UpdateDialogControls w/command handlers, which worked, (autoset focus to list box when last item was removed) but it requires more work:
to the .h add
<br />
afx_msg LRESULT OnKickIdle(WPARAM wParam, LPARAM lParam);<br />
to the .cpp add
<br />
ON_MESSAGE(WM_KICKIDLE, OnKickIdle)<br />
<br />
LRESULT CTestDlg::OnKickIdle(WPARAM wParam, LPARAM lParam)<br />
{<br />
UNREFERENCED_PARAMETER(wParam);<br />
UNREFERENCED_PARAMETER(lParam);<br />
UpdateDialogControls(this, FALSE);<br />
return (0);<br />
}<br />
<br />
* For each button that needs to be enabled/disabled:
in .h, add:
<br />
afx_msg void OnUpdatexxxButton(CCmdUI* pCmdUI);<br />
in .cpp add:
<br />
ON_UPDATE_COMMAND_UI(IDC_xxx_BUTTON, OnUpdatexxxButton)<br />
<br />
void CTestDlg::OnUpdatexxxButton(CCmdUI* pCmdUI)<br />
{<br />
pCmdUI->Enable(m_listBox.GetCurSel() != LB_ERR);<br />
}<br />
* You could also group their IDs if you wanted using ON_UPDATE_COMMAND_UI_RANGE
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Thanks Jack, I added loads of m_btnAdd.SetFocus() calls everywhere and now it works. I'm sure I did this before but obviously not...
Anyway thanks everyone for replying. Wicked.
Cheers
d3m0n
|
|
|
|
|
So why not just set the focus to one of the other controls, namely the listbox?
[d3m0n] wrote:
I tried adding a m_pbtnAdd->SetFocus() to the OnBtnRemove function, but it makes no difference.
Why would you put focus on a control that has been disabled?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
The Add button is never disabled. As I said, I already tried setting the focus to the Add button however this didn't work before. I've got it working this way now though.
Cheers
|
|
|
|
|
I made no reference to the Add button.
When I remove an item from a list, I expect the "next" item in the list to be selected, but the Remove button to retain focus. That way I can click the Remove button quickly from the keyboard. If there are no more items in the list, the Remove button should be disabled and the focus should go to some other control (e.g., the listbox or the Add button).
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
You did refer to the Add button, when you quoted me:
[d3m0n] wrote:
I tried adding a m_pbtnAdd->SetFocus() to the OnBtnRemove function, but it makes no difference.
Why would you put focus on a control that has been disabled?
So I was just saying that the Add button is not disabled
However I do agree with what you say about the focus remaining on the Remove button until there are no more items left in the listbox. I will try and implement this. Good idea.
Cheers
d3m0n
|
|
|
|
|
You're right. The indirect reference was my bad.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|