Reputation: 131058
A clear example of how data structures can be used in C++ is given [here].1 This is one of the examples given on the linked page:
struct product {
int weight;
float price;
} ;
product apple;
product banana, melon;
However, I have a code that does not follow this template and I cannot understand it. What I have is given bellow:
struct result : mppp::data::table <
row<semantics::user, int>,
row<semantics::exitdatum, spmm::date>,
row<userid, int>
> {};
I do not understand why instead of struct name we have such a complex construction and how it should be understood. Moreover, I do not understand why the "body" of the struct is empty (there is nothing between "{" and "}").
Can anybody please explain me that?
ADDED
Thank you for the answers. Now it is more clear. The :
in the above example means inheritance. But what all these structures mean: aaa<bbb>
?
Upvotes: 2
Views: 190
Reputation: 126432
That code uses inheritance. You can specify the base classes of a struct
after their name, separating them with a :
character and, possibly, using one of the public
, protected
, or private
qualifiers for specifying the type of inheritance (public
being the default if none is specified (*)):
struct A { }; // Fine
struct B : public A { }; // Also fine
struct C : B { }; // Fine again, `public` is assumed by default
struct D : A, B { }; // Also possible (multiple inheritance)
struct E { };
struct F : public E, private D { } // Qualifiers can differ
struct : A, F { } obj; // structs can be anonymous
In your case, the base class is an instance of a template:
template<typename T>
struct X { };
struct Y : X<A> { }; // Fine
class
types, the default is assumed to be private
in that case.
Upvotes: 7
Reputation: 258568
A struct
is equivalent to a class
(other than the default access level). You can inherit structs or classes just as well. mppp::data::table <
row<semantics::user, int>,
row<semantics::exitdatum, spmm::date>,
row<userid, int>
is just that - a specialized template class.
Upvotes: 0
Reputation: 23058
It is inheritance like the case in class
.
Therefore, in your example, struct result
inherits another class or struct mppp::data::table < row<semantics::user, int>, row<semantics::exitdatum, spmm::date>, row<userid, int> >
.
Upvotes: 1
Reputation: 399803
It is inheriting a template, but not adding any fields of its own.
You must read a C++ tutorial.
Upvotes: 2