Earlier quoted context omitted.
>The behavior of [] is from C -- it's not a bizarro C++ feature. I'd say that a feature of C++ is still a feature of C++ even if the same feature is in C.
The point was probably that it is not obscure; it's what you had to learn when using plain C in the first week.
Obscure C++ Features
41–50 of 58 posts
Re: Obscure C++ Features
#42Dark font on dark background. Unreadable.
Re: Obscure C++ Features
#43The behavior of [] is from C -- it's not a bizarro C++ feature. The "redefining keywords" is the pre-processor. That's what it does. There isn't anything magic here. Strictly speaking it can be run entirely ahead of the C/C++ compiler, on any file you want. There's no requirement that it is C/C++ - you could use it on a python script (as long as you weren't using # comments anywhere :D )
Moreover, 3[a] appears to be supported solely for backwards compatibility with C since it works only for pointers - you can't do this with classes which define operator[](int).
For example, I could do:
class MyClass {int operator+(int a) { return a; }};
MyClass x;
x + 1; // Valid.
1 + x; // Type error.
EDIT: My mistake. C++ requires these operators to be nonstatic member functions: = -> [] ()
Which, annoyingly enough, means that you can define '+' over types that you haven't implemented, but you can't define [] or =.Re: Obscure C++ Features
#44Earlier quoted context omitted.
I see this as no different than being able to do for (int i = 0; i
Imagine my surprise, getting out of college and trying to use this at my job, when the compiler told me it was invalid! It wasn't obscure to me, but apparently was to the Sun Studio C++ compiler.
Re: Obscure C++ Features
#45Earlier quoted context omitted.
Imagine my surprise, getting out of college and trying to use this at my job, when the compiler told me it was invalid! It wasn't obscure to me, but apparently was to the Sun Studio C++ compiler.
It was added in C99, I think.
Re: Obscure C++ Features
#46Obscure? You may think so but sometimes these things buy you lots of time.
Re: Obscure C++ Features
#47My favorite is that these are indeed "alternate operator tokens " an so you can use `compl` in place of ~ to name a destructor. Like, for explicit destruction: MyType* foo = ...; foo->compl MyType();
Bonus: Can you paste together the "compl" token with preprocessor macros?
Re: Obscure C++ Features
#48Re: Obscure C++ Features
#49Earlier quoted context omitted.
The point was probably that it is not obscure; it's what you had to learn when using plain C in the first week.
And the next week, and six months after that, again.