|
sorry toxcct I don't see you point!
toxcct wrote:
you wrote :
cout << a++ << endl << a.geti() << endl; equivalent to : cout << a.operator++() << endl << a.geti() << endl;
This is postfixed version, and a.operator++()shoud be in prefixed version.
toxcct wrote:
Now, i suggest writing instead :
cout << ++a << endl << a.geti() << endl; equivalent to : cout << a.operator++(1) << endl << a.geti() << endl;
This is prefixed version, and a.operator++(1) shoud be in postfixed version!
Finally I figured out why the result is incorrect:
in
cout << ++a << endl << a.geti() << endl;
The A::geti() gets called first that was before "i" get incremented
cout << ++a << endl ; cout << a.geti() << endl;
will produce the right result!But what exactly happened?
|
|
|
|
|
tss,
you finnally did what i told you from at the beginning...
what happened is that geti() got the value returned by postfixed ++ operator, that means, the old value, just because you were on the same instruction !!!
ps: sorry for the mix i made in my mind between operator++() and operator++(int). you are right
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
actually, prefix operator is not correct because it should return an l-value (e.g. int& instead of int). however, this implementation is not very logical, because increment operator should not return different type that the one where it is defined.
|
|
|
|
|
Zdeslav Vojkovic wrote:
actually, prefix operator is not correct because it should return an l-value (e.g. int& instead of int).
What do you mean by that?
Zdeslav Vojkovic wrote:
however, this implementation is not very logical, because increment operator should not return different type that the one where it is defined.
The implementation should look like:
A operator ++()<br> {<br> return A(++i); <br> }
?
|
|
|
|
|
Zdeslav Vojkovic wrote: actually, prefix operator is not correct because it should return an l-value (e.g. int& instead of int).
What do you mean by that?
Zdeslav Vojkovic wrote: however, this implementation is not very logical, because increment operator should not return different type that the one where it is defined.
The implementation should look like:
A operator ++()<br> {<br> return A(++i); <br> } ?
|
|
|
|
|
it should look like this:
A& operator ++()<br />
{<br />
++i; <br />
return *this;<br />
}
|
|
|
|
|
if you have a function which receives 2 parameters:
fn(a, b)
when you call it, parameters are evaluated from right to left and put on stack, so if you call:
fn( fn1(), fn2());
fn2 will be evaluated FIRST, and result put on stack. now, fn1 will be evaluated and put on stack, so
when fn() starts to execute, it will find first parameter (result of fn1) on the top of the stack, and second parameter right after it.
similar works for expression 'cout << a << b;'
it is iterpreted as
( cout.operator <<(a) ) .operator <<(b);
so when it is called, first expression 'b' is evaluated and then 'a'. after this, operator << is called twice. in your case, this means that 'a.geti()' is executed before 'a++'. even if you write '++a' you won't get the expected result.
|
|
|
|
|
Zdeslav Vojkovic wrote:
fn( fn1(), fn2());
I'm pretty clear with that!
But not with
Zdeslav Vojkovic wrote:
similar works for expression 'cout << a << b;'
'cout << a << b;' to me is like a two times function calls each with a single argument, eg.
(cout::operator<<(a))
and
(cout::operator<<(a)).operator<<(b)
what decide their calling sequence?
|
|
|
|
|
hey all ...im kinda new to this place .....so dunno whether im posting in the right place .....
I have to complete this thing in a span of 3 days ..i dunno how ...but here goes ...
Take a Jpeg image and convert it to text ...
Can i get som ekind of algorithm for this purpose...or even a JPEG image file format ?? Or even links to those ....
The links that i have tried .....give me the details as to how a JPEG image is made .... not how the file is arranged ..
Can someone guide me in this respect .....
Thanks ,
Jomy
|
|
|
|
|
Jomy John wrote:
I have to complete this thing in a span of 3 days
Jomy John wrote:
Take a Jpeg image and convert it to text ...
You want to write an OCR program in 3 days ?
Jomy John wrote:
Can i get som ekind of algorithm for this purpose...or even a JPEG image file format ?? Or even links to those ....
GDI+ will let you read/write JPEGs in C++, and even gives you elegant access to the bits of the image. There's no text inside a JPEG though, you need to examine the individual bits and work out for yourself which bits are letters.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
thanks a lot .....
I have finished reading a Jpeg file ...using the File format of Jpeg ....and have the charcters in hex ....
Now ...are there any hex encoding tables..or sum rule by which i can encode my hex set of numbers to a Sms character set ???
|
|
|
|
|
OK, so you want to turn it into a string in order to transmit it ? Here[^] is some info on BASE64 encoding.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
what is the meaning on a C++/CLI forum ?
perfectly stupid, and moreover, written as anonymous
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
I am a beginner of .Net progamming and I've got a C# project which needs to render PDF documents. I can create a Gdiplus::Bitmap object for each PDF page in unmanaged C++. I wrote a managed C++ wrapper class in which I tried to convert the pointer of Gdiplus::Bitmap to the pointer of System:: Drawing:: Bitmap, but I got the error message -- error C2440: '=' : cannot convert from 'Gdiplus::Bitmap *' to 'System:: Drawing:: Bitmap __gc *'
Thanks in advance.
|
|
|
|
|
i really need an answer to this question.. please help me..
|
|
|
|
|
You can find out about all the hardware on the computer in two ways :
1. From Windows Registers
2. Test for hardware yourself
I recommand you option no. 1. For this option I do not know the exact answer but try searching the internet, and in the meantime, look into the HKEY_LOCAL_MACHINE.
I hope you understand...because is a rough world out there...
|
|
|
|
|
Teacher: The Teacher asked the student to write
"I Will Not Throw Paper Airplanes in the Class"
500 times.
Student:
#include <stdio.h>
int main(void)
{
for(int count=0; count<=500; count++)
printf("I Will Not Throw Paper Airplanes in the Class\n");
}
-- modified at 3:05 Thursday 1st September, 2005
|
|
|
|
|
the student is so enthusiat that he's gonna print the line 501 times !!!
he should not use <= but <
anyway, i like it
cheers,
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 5:12 Thursday 1st September, 2005
|
|
|
|
|
If I write 500 times One time free.
500 times is for Teacher.
One is for him.
Thanks for reply.
|
|
|
|
|
A real C++ geek would write it this way:
fill_n(ostream_iterator<string>(cout, "\n"), 500, "I Will Not Throw Paper Airplanes in the Class");
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
|
I have in my project a template class. When I try to use a method in that class, then i get error messages like that:
C:\My Documents\tel_op3\tel_op3\info_dlg.cpp(14) : error C2228: left of '.setFilename' must have class/struct/union type
What could be the problem?
Thanks,
Chen
|
|
|
|
|
Include the header file of the class in the cpp file.
If this doesn't work, give more details because it is impossible to know what's happening with so little clues.
|
|
|
|