|
-
June 20th, 2002, 04:56 AM
#1
Is this possible? ;^)
#include <ostream.h>
#include "main.h"
void main()
{
UINT i = 0;
+++++++i----++;
cout << i << endl;
}
ZDF
What is good is twice as good if it's simple.
"Make it simple" is a complex task.
-
June 20th, 2002, 06:14 AM
#2
Why don't you implement it and find out?
experience is the best teacher
The search feature of this forum is on the top right of the page. It might be a very good idea to use it.
----------------
To retain respect for sausages and laws, one must not watch them in the making.
- Otto von Bismarck (1815-1898) -
-
June 20th, 2002, 06:21 AM
#3
until post increment yes (++++...i; ).
It is also possible to use microscope as hammer
The question is what for ?
-
June 20th, 2002, 06:39 AM
#4
-
June 20th, 2002, 06:47 AM
#5
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.
-
June 20th, 2002, 07:01 AM
#6
++++++ is no default operator and it wont be seen as a stack of operators, so you would have to define a custum operator
The search feature of this forum is on the top right of the page. It might be a very good idea to use it.
----------------
To retain respect for sausages and laws, one must not watch them in the making.
- Otto von Bismarck (1815-1898) -
-
June 20th, 2002, 07:52 AM
#7
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!
ZDF
What is good is twice as good if it's simple.
"Make it simple" is a complex task.
-
June 20th, 2002, 08:09 AM
#8
About UINT i was just serious. Never give well known things
not standard meaning.
-
June 20th, 2002, 08:16 AM
#9
Originally posted by Alexis Moshinsky
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.
Have a nice day!
ZDF
What is good is twice as good if it's simple.
"Make it simple" is a complex task.
-
June 20th, 2002, 08:28 AM
#10
Re: Is this possible? ;^)
Originally posted by zdf
#include <ostream.h>
#include "main.h"
void main()
{
UINT i = 0;
+++++++i----++;
cout << i << endl;
}
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:
Code:
// void main() This is an error
int main() // This is correct
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 
Regards,
Paul McKenzie
-
June 20th, 2002, 08:33 AM
#11
Re: Re: Is this possible? ;^)
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:
Code:
// void main() This is an error
int main() // This is correct
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 
Regards,
Paul McKenzie
Ooopssss! 
Thank you!
ZDF
What is good is twice as good if it's simple.
"Make it simple" is a complex task.
-
June 20th, 2002, 08:38 AM
#12
The chain of preincrements should be Ok with any compiler.
The whole line will not compile nowhere.
-
June 20th, 2002, 09:00 AM
#13
Originally posted by Alexis Moshinsky
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:
#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;
}
ZDF
What is good is twice as good if it's simple.
"Make it simple" is a complex task.
-
June 20th, 2002, 09:46 AM
#14
I meant of course predefinded data types, not user defined.
Nice evening to You too.
-
June 20th, 2002, 10:33 PM
#15
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; }
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|