2

Are java annotations the same thing with C# attributes? What is the equivalent in C++?

I found the solution of the first part of my question here. But what about C++? I think these kinds of mechanism are not possible in C++ because they request reflection and reflection doesn't exists in C++. Right?

Community
  • 1
  • 1
Bastien Vandamme
  • 17,659
  • 30
  • 118
  • 200

2 Answers2

2

Annotations are a form of metadata on the Java class and contained members/methods. They are distinct from compiler-scope keywords since they can persist in the compiled class and (as you've noted) available via reflection. I don't believe there's any equivalent in C++.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
0

You can add some attributes with gcc, see Declaring Attributes of Functions.

But this is very specific and not portable and not as flexible or extendable as Java annotations.

Although, it seems you can write compiler plugins, which extend the set of recognized attributes

GCC plugins may provide their own attributes.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198