|
Is there something wrong? I have a class by using manually GUI add class to generic class for a while the class to class that deriveded from CObject base class. The compiler has already this job be complated for the user's defination these classes just as in base defination?
modified 13-Mar-13 6:00am.
|
|
|
|
|
hi
i want to check whether variable in given generic array(like CArray) is CString or integer etc.I tried using IsKindOf but it doesn't work for CString.so is there any method for Runtime type Identification??
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
Correct me if I'm wrong but your array is a template array. So you have to declare something like this:
CArray<CString> myArray;
So, you know exactly what you declared, isn't it ?
|
|
|
|
|
QuickDeveloper wrote: I tried using IsKindOf but it doesn't work for CString
Use the (standardized) RTTI-feature of C++!
The only reason that IsKindOf exists is that MFC predates the C++-Standard.
Something like
CString* pCStr = dynamic_cast<cstring*>(vec[i]);
if( !pCStr)
{
...must be something different...
}
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
QuickDeveloper wrote: so is there any method for Runtime type Identification??
typeid()
|
|
|
|
|
Hello everyone,
1. Returning non-const reference to function local object is not correct. But is it correct to return const reference to function local object?
2. If in (1), it is correct to return const reference to function local object, the process is a new temporary object is created (based on the function local object) and the const reference is binded to the temporary object, and the life time of the temporary object is extended to the life time of const reference?
Or no need to create such a temporary object, just let the const reference binded to the function local object itself?
thanks in advance,
George
|
|
|
|
|
George_George wrote: 1. Returning non-const reference to function local object is not correct. But is it correct to return const reference to function local object?
You mean something like that ?
const int& Test()<br />
{<br />
int Temp = 42;<br />
return Temp;<br />
}
If that's what you mean then the answer is no, you can't do that (well technically you can but it is totally unsafe). The scope of the Temp variable is still limited to the Test function. So, outside your function you will hold a reference to an object that has been destroyed (when going out of scope at the end of the function).
You have to keep in mind that when you use reference, no copy of the object is being made (on the return or by passing a reference as an argument to a function).
|
|
|
|
|
Great reply, Cedric!
My question is answered.
regards,
George
|
|
|
|
|
Hi All,
I am developing a 'Text editor' kind of application. I have derived a class from 'CView' and i am doing all text editor relevant operations with this.
If i select some text and if i press 'Delete' button then my tool is deleting the selected text. But if i do the same thing without selecting the text then it is not deleting the characters.
That means without selecting some text delete operation is not working...
Can any one please tell me how can i handle this ???
Thanks & Regards
Sanjeeva Kumar
|
|
|
|
|
But if i do the same thing without selecting the text then it is not deleting the characters.
Can you tell me is the cursor is focused in edit box when you are deleting the text in edit box.
|
|
|
|
|
Hi Shashi,
Yes. cursor is focused in test editor.
I think i have not written code for handling the delete key event.
Please tell me if you know how to handle this ???
Thanks in advance
Sanjeeva Kumar.
|
|
|
|
|
Sanjeeva Kumar K wrote: I think i have not written code for handling the delete key event.
But did you not earlier state that, "If i select some text and if i press 'Delete' button then my tool is deleting the selected text."?
In your deletion code, are you first checking to see if any text is selected?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have written code for deleting characters only if some text is selected.
If i simply press the 'Delete' button then this function is not invoked.
do i need to handle it separately ???
Regards,
Sanjeeva Kumar.
|
|
|
|
|
Sanjeeva Kumar K wrote: do i need to handle it separately ???
I would think so.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I think u don't need to override the WM_KEYDOWN message. it will all happen automatically.
or if u need to override for some reason then call base implementation in overridden function
eg: If you are using the CEdit then you need to call the CEdit::OnKeyDown in ON_WM_KEYDOWN Message Handler function. Or if you are using a Win32 then u need call the Old Window procedure in your own window proc. i mean leave the deleting to the default message handler. that's it.
BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
ON_WM_KEYDOWN(OnMyEditeyDown)
END_MESSAGE_MAP()
void CMyEdit::OnMyEditeyDown( UINT nChar,
UINT nRepCnt,
UINT nFlags )
{
CEdit::OnKeyDown(nChar,nRepCnt,nFlags);
// to Do
}
i think this will help you
|
|
|
|
|
Thanks Nitheesh. I will try this.
|
|
|
|
|
Hi all,
For a long time I'm worried about this and still don't found the correct way.
Say I have a function as follows.
void addData(string name, char gender)
{
}
But I can't send name and gender to addData() function within a single function. One function find the name and another function find the gender.
void getName()
{
}
void getGender()
{
}
How can I send those values to the addData() function using two functions as shown above.
I appreciate your help all the time...
Eranga
|
|
|
|
|
You cannot have two different functions send one argument each to a function that accepts two arguments. I really don't understand your problem clearly though.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
what about:
void getName( string & name)
{
}
char getGender()
{
}
and then
string name;
char gender;
getName(name);
gender = getGender();
addData(name, gender);
?
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.
[my articles]
|
|
|
|
|
CPallini wrote: string name;
char gender;
getName(name);
I'm not clear this code. I mean that looking to find the name using getName() function.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: I'm not clear this code. I mean that looking to find the name using getName() function.
It assigns the found name to the passed parameter.
Could you please post your actual getName code?
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.
[my articles]
|
|
|
|
|
You actually understood his query? Man you're too good.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Rajesh R Subramanian wrote: You actually understood his query?
I try my best guessing about.
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.
[my articles]
|
|
|
|
|
CPallini wrote: I try my best guessing about.
I got that now.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Eranga Thennakoon wrote:
How can I send those values to the addData() function using two functions as shown above.
You can't. The two functions you've shown have no way of sending data back to the caller. If you are allowed to change them, something like:
string getName( void )
{
}
char getGender( void )
{
}
...
addData(getName(), getGender()); might work.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|