struct in c++ example
Example 1: function in struct c++
struct foo {
int bar;
foo() : bar(3) {} //look, a constructor
int getBar()
{
return bar;
}
};
foo f;
int y = f.getBar(); // y is 3
Example 2: struct c++
struct product {
int weight;
double price;
} apple, banana, melon;