|
the code you just posted:
void MyCallback( TreeItemType& anItem )
{
}
void main( void )
{
BinarySearchTree bst;
TreeItemType key(1);
bst.searchTreeInsert(key);
bst.preorderTraverse(MyCallback);
}
Its what I tried first, but i kept getting an error saying the the function MyCallBack(in your case) needs to return a FunctionType value.
|
|
|
|
|
According to the function's signature that you initially posted, it should return a void .
Member 3822532 wrote: Its what I tried first, but i kept getting an error saying the the function MyCallBack(in your case) needs to return a FunctionType value.
What line is the compiler complaining about?
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Yes, exactly! And that's why I'm frustrated!
the typedef definition in BST.h:
typedef void (*FunctionType)(TreeItemType& anItem);
That means the function FunctionType is void right?
or does it mean that it is of FunctionType value and thus needs to return that value?
I know that my misunderstanding of that one line of code is what is causing me all the problems.
|
|
|
|
|
Member 3822532 wrote: That means the function FunctionType is void right?
It means that it returns a void .
What does your implementation of this function look like?
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Sorry that's what I meant to say.
It returns void, but I keep getting the error that it needs to return the value FunctionType.
So here is the implementation.
This is what I did in response to the error.
I don't think this is right, but I got no error when I tried compiling the code.
FunctionType showNumber(TreeItemType& iTreeNumber)
{
return showNumber(iTreeNumber);
}
This causes a recursive error.
|
|
|
|
|
It should be:
void showNumber( TreeItemType& iTreeNumber )
{
cout << iTreeNumber.getKey();
}
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
yeah.
Before posting this problem on the boards, I had tried attaching void as the function sig:
void showNumber( TreeItemType& iTreeNumber )
{
cout << iTreeNumber.getKey();
}
and this is error i get:
"cpp(74) : error C2664: 'BinarySearchTree::preorderTraverse' : cannot convert parameter 1 from 'void' to 'FunctionType'"
then i tried this.
FunctionType showNumber( TreeItemType& iTreeNumber )
{
return showNumber(iTreeNumber);
}
for no error, but not the correct solution.
|
|
|
|
|
Then the problem is with code you've not shown. I've taken each of your code snippets and it compiles fine.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Wow, I wonder what it is then.
So you were able to call the BST's preorder traversal in main?
like so:
cTree1.preorderTraverse(showNumber(iFromTree));
By the way, thanks for all your quick responses.
|
|
|
|
|
Member 3822532 wrote: So you were able to call the BST's preorder traversal in main?
Exactly like this.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
damn... that works
I see what I did wrong now.
Thanks a lot for your help.
|
|
|
|
|
hi i am tryingto build astatic library. and while i build i get this fatal error, kindly help me rectify this.
fatal error C1083: Cannot open include file: 'BasicHashTable.hh': No such file or directory
|
|
|
|
|
if this is a C# question, it's in the wrong forum.
if it's a C++ question, then you have to either tell the compiler where to find BasicHashTable.hh or, put BasicHashTable.hh in a place where the compiler is already looking.
|
|
|
|
|
i have created a 5 Buttons dynamically.
eg :
2) Button 1 contol id :5000
1) Button 2 contol id :5001
1) Button 3 contol id :5002
1) Button 4 contol id :5003
1) Button 5 contol id :5003,
i need to select caption name "Button 1" using its control id 5000;
i used RButtonup and i got control id. But i dont know how to get the caption of Button .Please help.
|
|
|
|
|
Assuming your controls are in a dialog box: If you are using Win32 then you may call SendDlgItemMessage (with WM_GETTEXT or WM_SETTEXT , depending on your needs).
In a similar way you may use MFC 's CWnd::SendDlgItemMessage .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CWnd::SendDlgItemMessage,
i have no idia if you give example, it is very helpful to me.
|
|
|
|
|
Inside a method of your window class (the parent window of your buttons) call, for instance:
SendDlgItemMessage(5000, WM_SETTEXT, 0 , (LPARAM) _T("BUTTON 0"));
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
no i am not getting, please is there any sample code.
|
|
|
|
|
If you post your (relevant) code may be I can tell you how to modify it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
ON_COMMAND_RANGE(5000,5100,OnButtonRange)
void CTest::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
CButton* m_btDynamic;
CString csText;
int k=0;
for(int i=0;i<5;i++)
{
m_btDynamic = new CButton();
csText.Format(L"Button %d",i+1);
m_btDynamic->Create(csText, BS_FLAT|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_ICON,
CRect(10+k ,10+k,60+k,60+k),this, 5000+i);
k=k+30;
}
}
void CTest::OnButtonRange(UINT nIDforControl)
{
int iSelectedControlID;
iSelectedControlID = nIDforControl;
// here i want button caption
}
Where i should use SendDlgItemMessage()
|
|
|
|
|
Well, you already set the caption for you button with known values, so what's your need now?
BTW I suggest you to maintain the CButton pointers in a member variable:
in class declaration:
CButton * m_btDynamic[5];
then, in you function you may do
void CTest::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
CString csText;
int k=0;
for(int i=0;i<5;i++)
{
m_btDynamic[i] = new CButton();
csText.Format(L"Button %d",i+1);
m_btDynamic[i]->Create(csText,BS_FLAT|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_ICON,
CRect(10+k ,10+k,60+k,60+k),this, 5000+i);
k=k+30;
}
}
so that whenever you need to access the caption of, say, third button, you may call
m_btDynamic[2]->GetWindowText();
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
thanks CPallini,
this is not exact code i have posted.
in my actual code i have created 100 buttons, same way as u told. but the problem is if user right click on any button i want that caption.
|
|
|
|
|
You may do this way (in your event handler):
CButton * pClickedButton = (CButton *) GetDlgItem( id );
CString sClickedCaption = pClickedButton->GetWindowText();
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Friday, March 26, 2010 10:26 AM
|
|
|
|
|
i am getting error
error C2039: 'GetText' : is not a member of 'CButton'
|
|
|
|
|
Sorry, I should have fixed it now.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|