getting_started:cplusplus
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
getting_started:cplusplus [2015/10/14 14:22] – [Templates] graf | getting_started:cplusplus [2017/09/24 15:29] (current) – removed graf | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== C++ for Beginners ====== | ||
- | This is a very short introduction into a couple of concepts of C++. It should enable a beginner without knowledge in C++ to properly use EEROS in an own simple application. | ||
- | ===== Namespaces ===== | ||
- | With namespaces you can group entities such as classes or enums under a choosen name. In this way the global scope can be split into subscopes with distinguished names. EEROS heavely uses namespaces. | ||
- | In order to use declarations from these namespaces we can either import such a namespace or use the scope operator '::' | ||
- | <code cpp> | ||
- | using namespace eeros:: | ||
- | int main(int argc, char **argv) { | ||
- | StreamLogWriter w(std:: | ||
- | Logger< | ||
- | Logger< | ||
- | |||
- | eeros:: | ||
- | |||
- | using eeros:: | ||
- | Gain<> | ||
- | </ | ||
- | With 'using namespace eeros:: | ||
- | The block ' | ||
- | The block ' | ||
- | |||
- | ===== Using Constructors ===== | ||
- | Constructors - as any other function - can be overloaded. Many blocks you may want to use in your control system can be instantiated in various ways. Let us consider an example with a '' | ||
- | <code cpp> | ||
- | using namespace eeros:: | ||
- | int main(int argc, char **argv) { | ||
- | Gain<> | ||
- | Gain<> | ||
- | g2.setGain(10); | ||
- | } | ||
- | </ | ||
- | The first constructor initializes a gain block and sets its gain value to 10. The second instance of the same block is created with a gain value defaulting to 1. This value could then be subsequently set to 10. | ||
- | |||
- | ===== Templates ===== | ||
- | Function and class templates are widely used within the eeros framework. Templates allow the parametrization of many blocks and signals. This should be demonstrated with the example of a '' | ||
- | <code cpp> | ||
- | using namespace eeros:: | ||
- | using namespace eeros:: | ||
- | int main(int argc, char **argv) { | ||
- | Constant<> | ||
- | Constant< | ||
- | Constant< | ||
- | c1.run(); | ||
- | log.info() << c1.getOut().getSignal().getValue(); | ||
- | </ | ||
- | The square brackets - even if left empty - are necessary, because a '' | ||
- | Do not forget to call the method '' |
getting_started/cplusplus.1444825378.txt.gz · Last modified: 2015/10/14 14:22 by graf