. , , - - ( @Jesper Juhl).
, , , . ( # Groovy) ++, ++. SO ++. - Microsoft Visual ++ (, Microsoft Visual ++). Visual ++ MSDN. Visual ++, :
struct creature {
int numberofhands;
int fingersperhand;
__declspec(property(get = get_totalfingers))
int totalfingers;
private:
int fingers;
int get_totalfingers()
{
return numberofhands * fingersperhand;
}
};
:
#include <iostream>
int main()
{
creature martian;
martian.numberofhands = 2;
martian.fingersperhand = 4;
std::cout << "Total fingers: " << martian.totalfingers << std::endl;
return 0;
}
As I said before, properties are not a standard C ++ function, but there are ways to get them in C ++ that either rely on smart tricks or use compiler-specific functions. IMHO, using simple functions (as described by @Jesper Juhl), is a better alternative.
source
share