Reputation: 68
I know that hard brackets ('[' and ']') are used to identify an array, but whilst searching for how to use events I stumbled upon another use for them, and wonder what exactly it means...
The code I saw (link) looks like this:
// evh_native.cpp
#include <stdio.h>
[event_source(native)]
class CSource {
public:
__event void MyEvent(int nValue);
};
[event_receiver(native)]
class CReceiver {
public:
…
So...I wonder what exactly this means and what it is used for? Can someone please explain?
Upvotes: 3
Views: 148
Reputation: 234715
It could be a few things; to me it looks like your case is the last on my list:
To specify an index of an array.
To specify the capture list in a lambda expression or function.
[]
can be overloaded in a way that it detaches completely from its original intention. Boost spirit does this.
A non-standard compiler extension.
1, 2, and 3 can all be implemented in standard C++; 4 cannot.
Upvotes: 4
Reputation: 45434
Apart from the array usage and class operator[]
, there is another use in C++, the capture list of lambdas, like
int a;
auto func= [a](int i){ return i*a; }
but the example in your link looks like non-standard (it's referred to as native C++, whatever that is). Yet another use are double brackets for attributes, like
[[noreturn]] void throw_error(std::string const&message);
Upvotes: 5