#include <ostream.h>
#include "main.h"
void main()
{
UINT i = 0;
+++++++i----++;
cout << i << endl;
}
Printable View
#include <ostream.h>
#include "main.h"
void main()
{
UINT i = 0;
+++++++i----++;
cout << i << endl;
}
Why don't you implement it and find out?
experience is the best teacher :)
until post increment yes (++++...i; ).
It is also possible to use microscope as hammer :D
The question is what for ?
What if UINT is a class in "main.h"? And... what if you overload some operators?Quote:
Originally posted by Alexis Moshinsky
until post increment yes (++++...i; ).
It is also possible to use microscope as hammer :D
The question is what for ?
It's just a question. Does it make you think? :D
I do not know what for You prepare Yourself.
In my company if some young softhead write a class
named UINT, he/she will be fired immediately.
++++++ is no default operator and it wont be seen as a stack of operators, so you would have to define a custum operator
It may be a stupid problem but it points out what Mr. Moshinsky said some time ago: “C++ is not only its own language. It is most powerful language of the world.” (At least among the programming-languages I know.:) )
A solution may be:
class UINT
{
public:
UINT( unsigned int ad = 0 ) { d = ad; }
UINT& operator++(int) { ++d; return *this; }
UINT& operator++() { ++d; return *this; }
UINT& operator+() { return *this; }
UINT& operator--(int) { --d; return *this; }
UINT& operator--() { --d; return *this; }
friend ostream& operator<<(ostream& os, UINT& ui) { os << ui.d; return os; }
protected:
unsigned int d;
};
Have a nice day!
About UINT i was just serious. Never give well known things
not standard meaning.
Well, of course you are right! But I had to find a pretext to line up some signs otherwise you could not.Quote:
Originally posted by Alexis Moshinsky
About UINT i was just serious. Never give well known things
not standard meaning.
Have a nice day!
Using an ANSI C++ compiler -- this wouldn't even compile. Even if you did have some header called ostream.h and main.h, and you did have a class called UINT, this code won't compile for the following reason:Quote:
Originally posted by zdf
#include <ostream.h>
#include "main.h"
void main()
{
UINT i = 0;
+++++++i----++;
cout << i << endl;
}
So is this possible? Not with a conforming compiler. There are compilers now that flag it as an error, so I can't wait when VC++ is really ANSI compliant and starts to flag that line as an error. The surprised look on the faces of programmers will be a sight to see :)Code:// void main() This is an error
int main() // This is correct
Regards,
Paul McKenzie
Ooopssss! :eek:Quote:
Originally posted by Paul McKenzie
Using an ANSI C++ compiler -- this wouldn't even compile. Even if you did have some header called ostream.h and main.h, and you did have a class called UINT, this code won't compile for the following reason:
So is this possible? Not with a conforming compiler. There are compilers now that flag it as an error, so I can't wait when VC++ is really ANSI compliant and starts to flag that line as an error. The surprised look on the faces of programmers will be a sight to see :)Code:// void main() This is an error
int main() // This is correct
Regards,
Paul McKenzie
Thank you!
The chain of preincrements should be Ok with any compiler.
The whole line will not compile nowhere.
I have already compiled with VC++. It works fine. The displayed value is 2. This is the code:Quote:
Originally posted by Alexis Moshinsky
The chain of preincrements should be Ok with any compiler.
The whole line will not compile nowhere.
#include <ostream.h>
class UINT
{
public:
UINT( unsigned int ad = 0 ) { d = ad; }
UINT& operator++(int) { ++d; return *this; }
UINT& operator++() { ++d; return *this; }
UINT& operator+() { return *this; }
UINT& operator--(int) { --d; return *this; }
UINT& operator--() { --d; return *this; }
friend ostream& operator<<(ostream& os, UINT& ui) { os << ui.d; return os; }
protected:
unsigned int d;
};
void main()
{
UINT i = 0;
+++++++i----++;
cout << i << endl;
}
I meant of course predefinded data types, not user defined.
Nice evening to You too.
Normally when people see code like this: +++++++i----++;, he will be surprised. Following the standard way of doing as what the int does provided in C++ libraries is recommended, the better way is to add the const before the operator++ or etc to prevent operation like ++++++i----; the way of +++++++i----++; is good for exercise only. :)
const UINT& operator++(int) { ++d; return *this; }