|
<br />
vector<int> myIntVector;<br />
vector<int>::iterator myIntVectorIterator;<br />
<br />
myIntVector.push_back(1);<br />
myIntVector.push_back(4);<br />
myIntVector.push_back(8);<br />
<br />
for(myIntVectorIterator = myIntVector.begin(); <br />
myIntVectorIterator <= myIntVector.end();<br />
++myIntVectorIterator)<br />
{<br />
cout<<*myIntVectorIterator<<" ";<br />
}<br />
|
|
|
|
|
This code crashes on windows.
while on gcc 2.95.3 on unix
I get an output like
1 4 8 0
|
|
|
|
|
vikrams wrote: while on gcc 2.95.3 on unix
I get an output like
1 4 8 0
That's wrong. The code should throw an exception because you try to access the contents of an iterator outside the bounds of your vector.
|
|
|
|
|
Cedric Moonen wrote: That's wrong. The code should throw an exception because you try to access the contents of an iterator outside the bounds of your vector.
The C++ standard does not require an exception to be thrown in this case. The behaviour is undefined.
Steve
|
|
|
|
|
vikrams wrote: while on gcc 2.95.3 on unix
I get an output like
1 4 8 0
I think your gcc 2.95.3 sucks and you should stop using it right now.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
What's the problem ?
Anyway, AFAIK, you can only check for equality on iterators (don't know if that is the case also on vector iterator). This your end loop condition should be:
myIntVectorIterator != myIntVector.end();
EDIT: I tested and you can do that with vector iterators (for list iterators, you can't). Anyway the problem is that you have to stop incrementing your iterator before the end of your vector. So replace <= by < . Otherwise, if you are at the end of your vector (not a valid element), you will still try to access the contents of the iterator (which is invalid).
|
|
|
|
|
You are going past the end of the iterator, change the code to something like this:
vector<int> myIntVector;
myIntVector.push_back(1);
myIntVector.push_back(4);
myIntVector.push_back(8);
vector<int>::iterator iStart = myIntVector.begin();
vector<int>::iterator iEnd = myIntVector.end();
while(iStart != iEnd)
{
cout << *myIntVectorIterator << " ";
++iStart;
}</int></int></int>
|
|
|
|
|
Thanks for your suggestions guys !
|
|
|
|
|
HI all,
i want to call a dialog box when i pressed a button which is at bottom side,the dialog box should be positioned on exact upper part of the button
how could i do dis?
plzzzzz help me
Pankaj
modified on Friday, April 11, 2008 6:36 AM
|
|
|
|
|
You can use of DoModal or ShowWindow after you clicked button and then use of MoveWindow.
|
|
|
|
|
Hello everyone,
Here is the comments from the book ATL Internals about in-process server considerations,
--------------------
Any thread that calls CoGetClassObject or CoCreateInstance must already have joined an apartment, or the call will fail immediately. So, does that mean all objects exposed from in-process servers must be equally at home in single-threaded and multithreaded apartments so that random clients isn't cause harm? Fortunately, no.
--------------------
Does it mean COM client (thread) and COM server no need to be the same type of thread model (e.g. STA, MTA, etc.)?
thanks in advance,
George
|
|
|
|
|
George_George wrote: Does it mean COM client (thread) and COM server no need to be the same type of thread model (e.g. STA, MTA, etc.)?
No. If the threading models are compatible direct communication occurs. If the threading models are incompatible the object is created in an apartment it can "live in" and the interface pointer is marshaled back to the caller -- communication occurs via a proxy and stub. This is one of COM’s key features.
Steve
|
|
|
|
|
Thanks Steve,
How do you understand the quoted statements from my original question?
regards,
George
|
|
|
|
|
I'm just going off my knowledge of COM.
Steve
|
|
|
|
|
Are you kidding, Steve? You are COM expert, I know. How do you understand the statement in the book?
regards,
George
|
|
|
|
|
George_George wrote: Here is the comments from the book ATL Internals about in-process server considerations,
--------------------
Any thread that calls CoGetClassObject or CoCreateInstance must already have joined an apartment, or the call will fail immediately. So, does that mean all objects exposed from in-process servers must be equally at home in single-threaded and multithreaded apartments so that random clients isn't cause harm? Fortunately, no.
--------------------
Any thread that calls CoGetClassObject or CoCreateInstance must already have joined an apartment, or the call will fail immediately.
This part is pretty straight forward.
So, does that mean all objects exposed from in-process servers must be equally at home in single-threaded and multithreaded apartments so that random clients isn't cause harm?
This just seems to be another way of stating the question you asked.
Fortunately, no.
This is saying that the threading models of the client and server do not have to match but goes into no details on how this is achieved.
Steve
|
|
|
|
|
Thanks Steve,
Question answered. Congratulations to get all COM knowledge back.
have a good weekend,
George
|
|
|
|
|
In my app, i switch to a new desktop and pop up a dialog with an ActiveX control (Flash object) but got an erre msg in new desktop:
Debug Assertion Failed!
...
File: f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\oleinit.cpp
Line: 78
But if i pop up this dialog in current desktop,it's fine.
Pls help me !
|
|
|
|
|
I switch using CreateDesktop (GENERIC_ALL...) and SwitchDesktop().
|
|
|
|
|
Could you give some code ?
|
|
|
|
|
Dear Friends,
How to know whether the mouse button is Down
even if it moving.The WM_LBUTTONDOWN message is fired
only for the first time left button is pressed.
But how to know whether it is pressed all the time
though it may be moving.
|
|
|
|
|
|
Calling GetKeyState may be a better choice as it reflects state of the button when the current message was generated.
Steve
|
|
|
|
|
I'm sure that's what I meant
Thanks Steve!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
poda wrote: How to know whether the mouse button is Down
even if it moving.
Add event handler for WM_MOUSEMOVE . If the WPARAM for this event has MK_LBUTTON set then left mouse button is down, or if it has MK_MBUTTON , MK_RBUTTON then the corresponding mouse button is down!
If you are using MFC then use void OnMouseMove( UINT nFlags, CPoint point ).
nFlags will contain appropriate flags to indicate whether left, middle, right buttons or whether shift key is down. Use bitwise and to find out.
E.g.
if(( nFlag & MK_LBUTTON ) == MK_LBUTTON )
AfxTrace( "You are dragging the mouse\n" );
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
modified on Friday, April 11, 2008 2:58 AM
|
|
|
|