|
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
|
|
|
|
|
Rajesh R Subramanian wrote: What in the world does C++ have to do with that code?
Perhaps the C++ compiler, once overwent its perplexities, will try to compile it.
(Just kidding).
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
|
|
|
|
|
1) this is C
2) this code is for Borland compiler, and you are you a Visual C++ forum
3) please use the <pre></pre> tags (not <code> )to format your code samples
4) post relevant pieces of code, not a huge entiere source file
5) Read the posting Guidelines at the beginning of this forum
6) what's you question actually ?
|
|
|
|
|
I really think nobody will seriously answer to you if you don't cricubscribe your problem.
No one will read tens of noob code...
If you want to create a trivia-program, the best solution is collect questions and their respective
answers on a text file, than create a more structured engine that reads them and determines if
answers are right or not.
You can't improve randomization untill you have a more efficient question-selection engine.
Didn't you mean to compile your code avery time you add a new question ?
Remember, never post long code chunks if not necessary... time is worthy 4..
bye
|
|
|
|
|
You need a structure of some sort to hold:
The question
The list of possible answers
The correct answer
Something like:
struct _Trivia
{
string strQuestion;
vector<string> vecChoices;
string strAnswer;
};
"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
|
|
|
|
|
Hello all,
I have created one outlook addin.
In which ihave made one toolbar and button. Now when i click on button i want to show one dialog box.
I am able to show dialog box but the style of dialog box is of type windows 98 style even when i create it in design view, it is of the type Xp style.
Any body tell me what should i do so that the dialog box apear in Xp style.
Its realy eargent. I am newbe to outlook addin
Thanks i advance
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
dear all
sorry to ask so basic question, i am newcomer, when i compiled, if some errors occurred, always show C2668 or C2783, what is C2669 and so forth? the following question is what i mentioned in title. thanks a lot.
gentleguy
|
|
|
|
|
Which sqrt are you referring to?
The CRT function sqrt() has four overloads...you need to provide enough
info about the types of the return value and the passed argument so
the compiler knows which one to use.
int n = sqrt(3);
double d = sqrt(2.0);
int n = (int)sqrt((double)3);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello everyone,
Two questions,
1.
The following compiler error from the following code segment, is because delete statement from destructor of auto_ptr requires the declaration of destructor of wrapped object?
1>main.cpp
1>d:\visual studio 2008\projects\test_autoptr2\test_autoptr2\main.cpp(10) : error C2512: 'Foo' : no appropriate default constructor available
#include <memory>
#include <iostream>
using namespace std;
class Foo;
void func()
{
auto_ptr<Foo> pf (new Foo());
cout << "I am here. " << endl;
return;
}
int main()
{
func();
return 0;
}
class Foo {
};
2.
If yes, how to define a destructor outside of the body of class declaration? I defined in this way, but compile can not pass.
Foo::~Foo()
{
}
thanks in advance,
George
|
|
|
|
|
George_George wrote: 1.
The following compiler error from the following code segment, is because delete statement from destructor of auto_ptr requires the declaration of destructor of wrapped object?
the compiler error statement shows error on costructor and why you suspect the destructor.
auto_ptr<Foo> pf (new Foo()); and the eror is not related to autoptr, it is pointing to the statement with in it, "new Foo()" this requires the declaration of Foo to be visible.
And why do you given a forward declaration of class Foo.
|
|
|
|
|