|
The function readch() reads a character. But what do I use to "read a character, but do not wait for him to type a character?" How can the program find if there is a character waiting in the standard-input buffer?
|
|
|
|
|
|
*?#! You were faster.
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
|
|
|
|
|
|
This one [^] looks promising.
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
|
|
|
|
|
Hello everyone,
Suppose I have a component (class) CX implements IUnknown interface, and I have retrieved a pointer of CX by IUnknown pointer (IUnknown*), that is.
IUnknown* pCX;
QueryInterface (IID_IUnknown, &pCX);
delete pCX;
Even if I declare the component CX's destructor as virtual, if I delete through IUnknown pointer to "release" the object, there is still potential memory and resource leak, because in IUnknown interface, destructor is the compiler provided default one, which is non-virtual and public, right?
thanks in advance,
George
|
|
|
|
|
NEVER do that. COM has its own mechanism to perform cleanup, you must not break the toy.
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
|
|
|
|
|
Thanks CPallini,
I should ask the question in another way. Is the default destructor virtual or not?
regards,
George
|
|
|
|
|
Default destructor is not virtual.
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
|
|
|
|
|
Thanks CPallini,
Question answered.
regards,
George
|
|
|
|
|
George_George wrote: because in IUnknown interface, destructor is the compiler provided default one, which is non-virtual and public, right?
yes, But why don't you use Release() that's the COM needs.
|
|
|
|
|
Thanks Rajkumar,
I should ask the question in another way. The default destructor is non-virtual and public, right?
regards,
George
|
|
|
|
|
George_George wrote: The default destructor is non-virtual and public, right?
and your previous one
"destructor is the compiler provided default one, which is non-virtual and public, right?"
George_George wrote: I should ask the question in another way
I can understand that the above two has no difference, you can try something different that shows the difference of your question.
|
|
|
|
|
Thanks Rajkumar,
Sorry English is not my native language. I think you have answered my question, the default destructor is not virtual and it is public, right?
regards,
George
|
|
|
|
|
George_George wrote: I think you have answered my question
yes.
|
|
|
|
|
Thanks Rajkumar,
Question answered.
regards,
George
|
|
|
|
|
George_George wrote: if I delete through IUnknown pointer to "release" the object, there is still potential memory and resource leak, because in IUnknown interface, destructor is the compiler provided default one, which is non-virtual and public, right?
Right, except that strictly speaking you get "undefined behavior" which may or may not be a memory leak (with VC++, I bet it is a memory leak).
|
|
|
|
|
Thanks Nemanja,
Question answered.
regards,
George
|
|
|
|
|
The correct way is:
<br />
IUnknown* pCX;<br />
HRESULT hr = QueryInterface (IID_IUnknown, &pCX);<br />
if (!FAILED(hr))<br />
{<br />
pCX->Release();<br />
}<br />
delete cannot achive many of what COM interfaces are about:
reference counting:
Many clients might use the same object. You must not delete it before everyone else is done with it.
Use Release() to indicate "I am done with the object". The object will delete itself when it is no longer needed.
language independence
The object bight be implemented in VB, or Delphi, or one of many other languages. delete cannot correctly release an object that is implemented in another language.
Even if the object was implemented in C++, delete is likely to fail: a virtual destructor helps only when the object was allocated by the same memory manager.
location independence
COM allows to use objects in a separate process or even on another computer without really knowing about it. How is C++' delete going to delete an object on a server in hawaii? Some such relocations may be activated by registry configuration, independent of your code.
You need to follow the Reference Counting Rules[^] of COM.
Using smart pointers make that somewhat easier.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP blog: TDD - the Aha! | Linkify!| FoldWithUs! | sighist
|
|
|
|
|
Thanks peterchen,
Comprehensive reply.
regards,
George
|
|
|
|
|
Hai all,
If any body knows to embedd a manifest file to vc6, please help me. Mmanifest file for elevete user security.
Thanks in advance
Regards
Vicky00000
|
|
|
|
|
|
hi i wrote a trivia program but i want to improve it by randomizing the questions in it. but how do i do it? thanks
<br />
main()<br />
{<br />
int l;<br />
clrscr();<br />
gotoxy(30,7);printf("[1] QUESTIONS\n");<br />
gotoxy(30,9);printf("[2] QUIT\n\n");<br />
gotoxy(30,13);printf("Choose: ");<br />
scanf("%d",&l);<br />
if(l==1)<br />
easy();<br />
else if(l==2)<br />
exit();<br />
}<br />
easy()<br />
{<br />
int x;<br />
char d[5];<br />
int i=0;<br />
char a[]="a";<br />
char b[]="b";<br />
char c[]="c";<br />
for(x=0;x<=3;x++)<br />
{<br />
clrscr();<br />
gotoxy(10,5);printf("Direction: Choose the letter of the correct answer.");<br />
gotoxy(10,7);printf("1. What two letters are both symbols for 1,000?");<br />
gotoxy(10,9);printf("%s. K and M.",a);<br />
gotoxy(10,11);printf("%s. A and B.",b);<br />
gotoxy(10,13);printf("%s. L and D",c);<br />
gotoxy(10,15);printf("Answer: ");gets(d);<br />
if(strcmp(d,a)==0)<br />
{<br />
gotoxy(12,20);printf("Correct!!!\n");<br />
i=i+1;<br />
gotoxy(12,21);printf("Your score is %d",i);<br />
x=3;<br />
getch();<br />
}<br />
if(strcmp(d,a)!=0)<br />
{<br />
gotoxy(12,20);printf("Wrong!!!\n");<br />
gotoxy(12,21);printf("Life[%d]",x);<br />
getch();<br />
if(x>=3)<br />
{<br />
main();<br />
}<br />
}<br />
}<br />
for(x=1;x<=3;x++)<br />
{<br />
clrscr();<br />
gotoxy(10,7);printf("2. What's short for Binary Digit?");<br />
gotoxy(10,9);printf("%s. BD.",a);<br />
gotoxy(10,11);printf("%s. Bit.",b);<br />
gotoxy(10,13);printf("%s. Digit.",c);<br />
gotoxy(10,15);printf("Answer: ");gets(d);<br />
if(strcmp(d,b)==0)<br />
<br />
{<br />
gotoxy(12,20);printf("Correct!!!\n");<br />
i=i+1;<br />
gotoxy(12,21);printf("Your score is %d",i);<br />
x=3;<br />
getch();<br />
}<br />
else<br />
{<br />
gotoxy(12,20);printf("Wrong!!!\n");<br />
gotoxy(12,21);printf("Life[%d]",x);<br />
getch();<br />
if(x>=3)<br />
{<br />
main();<br />
}<br />
}<br />
}<br />
for(x=1;x<=3;x++)<br />
{<br />
clrscr();<br />
gotoxy(10,7);printf("3. What digit did Arab mathematician al-Khwarizmi give to the West\n around 800 B/B.?");<br />
gotoxy(10,10);printf("%s. Zero",a);<br />
gotoxy(10,12);printf("%s. One",b);<br />
gotoxy(10,14);printf("%s. Two",c);<br />
gotoxy(10,16);printf("Answer: ");gets(d);<br />
if(strcmp(d,a)==0)<br />
<br />
{<br />
gotoxy(12,20);printf("Correct!!!\n");<br />
i=i+1;<br />
gotoxy(12,21);printf("Your score is %d",i);<br />
x=3;<br />
getch();<br />
}<br />
else<br />
{<br />
gotoxy(12,20);printf("Wrong!!!\n");<br />
gotoxy(12,21);printf("Life[%d]",x);<br />
getch();<br />
if(x>=3)<br />
{<br />
main();<br />
}<br />
}<br />
}<br />
for(x=1;x<=3;x++)<br />
{<br />
clrscr();<br />
gotoxy(10,7);printf("4. What word describes a number system with a base of two?");<br />
gotoxy(10,9);printf("%s. Decimal",a);<br />
gotoxy(10,11);printf("%s. Octal",b);<br />
gotoxy(10,13);printf("%s. Binary",c);<br />
gotoxy(10,15);printf("Answer: ");gets(d);<br />
if(strcmp(d,c)==0)<br />
<br />
{<br />
gotoxy(12,20);printf("Correct!!!\n");<br />
i=i+1;<br />
gotoxy(12,21);printf("Your score is %d",i);<br />
x=3;<br />
getch();<br />
}<br />
else<br />
{<br />
gotoxy(12,20);printf("Wrong!!!\n");<br />
gotoxy(12,21);printf("Life[%d]",x);<br />
getch();<br />
if(x>=3)<br />
{<br />
main();<br />
}<br />
}<br />
}<br />
for(x=1;x<=3;x++)<br />
{<br />
clrscr();<br />
gotoxy(10,7);printf("5. How many equal sides does an icosahedron have?");<br />
gotoxy(10,9);printf("%s. Ten",a);<br />
gotoxy(10,11);printf("%s. Twenty",b);<br />
gotoxy(10,13);printf("%s. Thirty",c);<br />
gotoxy(10,15);printf("Answer: ");gets(d);<br />
if(strcmp(d,b)==0)<br />
<br />
{<br />
gotoxy(12,20);printf("Correct!!!\n");<br />
i=i+1;<br />
gotoxy(12,21);printf("Your score is %d",i);<br />
x=3;<br />
getch();<br />
}<br />
else<br />
{<br />
gotoxy(12,20);printf("Wrong!!!\n");<br />
gotoxy(12,21);printf("Life[%d]",x);<br />
getch();<br />
if(x>=3)<br />
{<br />
main();<br />
}<br />
}<br />
}<br />
<br />
}<br />
modified on Friday, March 21, 2008 2:27 AM
|
|
|
|
|
It Looks like a mess. What about a tutorial on (at least) structured programming?
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
|
|
|
|
|
What in the world does C++ have to do with that code?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|