|
Just playing devil's advocate...
But you're not adding i twice, you're adding the results of the expression ++i which is either going to be 3 or 4 depending on how many times you've done the ++ operation.
Cheers,
Ash
|
|
|
|
|
...but if you add 3 and 4 you will not get 8, and the OP would not have been confused in the first place. It would be a shame if once in a while you didn't get an unexpected result. (The testing department might disagree on that though)
|
|
|
|
|
This is a common issue and the rules are: don't do this as the results are not guaranteed. Whatever answer you get you may get a different answer with another manufacturer's compiler. If you really need to evaluate such an expression you need to break it into steps like:
int i = 2;
int j = ++i;
j += ++i;
It's time for a new signature.
|
|
|
|
|
It's pretty subtle. Here's a breakdown of what's hapenning:
++i increments i (so i =3) and returns a reference to i .- The second
++i increments i (so i =4) and returns a reference to i . - The
+ is called with the two references. Both are dereferenced and added (4+4).
Steve
|
|
|
|
|
int i = 2;<br />
<br />
int j = ++i + i++ + ++i + i++ + ++i;<br />
<br />
cout<<"Value of j: "<<j;
The value getting for 'j' is 19. As you have said the three ++i statements will execute and the value of i become 5. How will execute the i++ statements? Could you please explain.
|
|
|
|
|
Firstly there are two cases here, the pre-increment and (++i ) the post-increment (i++ ). The pre-increment case increments the variable and returns a reference to it. The post-increment case copies the variable, increments the original and returns the copy.
Steve
|
|
|
|
|
To reinforce what Richard said, while this is cute, it's always counterproductive. It's so subtle that even if you KNOW what you're doing, you're going to screw it up and in a production environment, you're going to confuse someone who's not was good with obfurscated code as you think you are. Just write it out in the clearest possible terms and let the compiler worry about optimizing it these days. The compiler can do optimizations that would curl your hair if you looked at what it was doing.
Once you agree to clans, tribes, governments...you've opted for socialism. The rest is just details.
|
|
|
|
|
Hi all
i have been experimenting with CAsyncSocket and have derived my own class. I am able to connect a client to a server app that I have written (VC6) and all is working well.
My first question is why does the server have to accept on another socket?
My second question is if the server is to be designed to accept 64 clients connecting to it, does that mean I need to define 128 sockets
Thanks for having a look at this!
Regards
Mike
|
|
|
|
|
MikeRWinter wrote: My first question is why does the server have to accept on another socket?
TCP is a connection oriented protocol, the server needs to accept the connection and a handshake is performed before further communication will be possible (which is part of TCP's reliable data transfer). On the other hand, if you are working with UDP, which is not connection oriented, you don't have to call accept(), sockets can just send data when they feel like (which could also mean nobody is listening to them).
MikeRWinter wrote: My second question is if the server is to be designed to accept 64 clients connecting to it,
Where does this limit come from, not sure what you mean?
/Moak
|
|
|
|
|
Greetings,
I am trying to populate a CTabCtrl in my dialog with child dialogs but I am having terrible problems with inheritance of the CWnd*.
Now I assume that is what it is as the dialogs I create are spawning in their own window rather than the client window of the control. Below is snippet of my class
CTabManage::CTabManage()
{
m_tab[0]=new CDetails;
...
void CTabManage::Init()
{
m_tabActive=0;
m_tab[0]->Create(IDD_TAB_DETAILS, this);
...
and here is where it is initialised
::OnInitDialog()
...
m_cTabManage.InsertItem(0, _T("Details"));
m_cTabManage.Init();
...
Any pointers would be appreciated as it has been driving me nuts.
Alan
|
|
|
|
|
Is the WS_CHILD set for you child dialogs? In the resource properties for your dialogs make sure Style=Child , and you probably would like Control=True as well.
|
|
|
|
|
Thank you. That got it.
That was the one thing I had not checked.
Alan
|
|
|
|
|
Hi everyone,
Can anyone tell me how to convert a vector (of doubles) to a variant?
I am receiving the following error message from vc++ 2008:
error C2664: 'CiPlotChannelX::AddXYArrays' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'const VARIANT &'
I have close to 1 million values so I'm trying to avoid any "for" loops.
Thanks!
|
|
|
|
|
Never needed to do this but i read somewhere that you can use CComSafeArray[^] to get a variant, or something that you can use with variant from an array. I think you need to wrap your array into this CComSafeArray thing (it is a template i believe) and then use Detach or maybe it's LPSAFEARRAY operator to get a SAFEARRAY wich can be used with VARIANT.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers don't kill programs, users kill programs <
> "It doesn't work, fix it" does not qualify as a bug report. <
|
|
|
|
|
ok, thanks. I'll look into this.
|
|
|
|
|
I have created a custom class to draw radio button and I am able to create it using the class object, but I want to imiplement group property on the radio button.
Can anybody please help me in this regards.
Thanks....
|
|
|
|
|
You should be a tiny bit more specific than that...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers don't kill programs, users kill programs <
> "It doesn't work, fix it" does not qualify as a bug report. <
|
|
|
|
|
I have a class CCustomRadioCtrl which is derived from cbutton with radio button style. using the object of my custom class I can create radio button, I am not able to set the group property of the radio button if I hv more then one radio control, So that one can be selected at a time.
|
|
|
|
|
What do you mean by "not able to set it"? You use something like ::SetWindowLong(hRadioBtn, GWL_STYLE, ::GetWindowLong(hRadioBtn, GWL_STYLE) | WS_GROUP) but it gives you an error code? You can't set the group style in the resource editor? You can set it but it just does not work? If it is the later one, what happens? Is your radio owner-drawn (has the BS_OWNERDRAW) style? If no, then i guess BS_AUTORADIOBUTTON should make it work. If yes, then, since according to the documentation[^] BS_OWNERDRAW can't be combined with anything else, you will have to provide this functionality manually. You can try using CheckRadioButton[^], i don't know if it works for owner-drawn buttons or not. Other than that what you can do i guess is use GetNextWindow[^] to walk the controls around the radio that has been clicked and find the other radios inside the same group and check/uncheck them.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers don't kill programs, users kill programs <
> "It doesn't work, fix it" does not qualify as a bug report. <
|
|
|
|
|
Can you send me some sample code, please ?
|
|
|
|
|
Of what?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers don't kill programs, users kill programs <
> "It doesn't work, fix it" does not qualify as a bug report. <
|
|
|
|
|
Hi!
I got the following compiler error.
error C2491: 'CEGUI::IrrlichtRenderer::d_rendererID' : definition of dllimport static data member not allowed
I've not imported any dlls. I've declared the variable "d_rendererID" in the header file as static with a
protected access specifier.
static String d_rendererID;
and I'm defining it in the source file like this:
String IrrlichtRenderer::d_rendererID("CEGUI::IrrlichtRenderer "
"- Official Irrlicht based 2nd generation renderer module.");
What is the thing that prevents the definition of this variable? How do I resolve?
|
|
|
|
|
All error codes can be found on MSDN with a better description -> C2491[^]
What is String? A class or a #define?
#define String __declspec(dllimport) std::string
could result in such error.
|
|
|
|
|
hi i want to open and play a video file in pocket pc 2003 using vc++.
please any idea any sample code which will help me.
|
|
|
|
|