User Tools

Site Tools


getting_started:cplusplus

This is an old revision of the document!


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 '::'. Let's look at an example.

using namespace eeros::logger;
int main(int argc, char **argv) {
	StreamLogWriter w(std::cout);
	Logger<LogWriter>::setDefaultWriter(&w);
	Logger<LogWriter> log;
 
	eeros::control::Constant<std::array<double,4>> c1;
 
	using eeros::control::Gain;
	Gain<> g1;

With 'using namespace eeros::logger' all the declarations in this namespace are made visible and can be directly used.
The block 'Const' within the namespace 'eeros::control' is used with the aid of the scope operator.
The block 'Gain' within the namespace 'eeros::control' is made available by 'using eeros::control::Gain;' and can be referred to further on without qualifying with the namespace.

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 Gain block.

using namespace eeros::control;
int main(int argc, char **argv) {
	Gain<> g1(10);
	Gain<> g2;
	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 set separately to 10.

getting_started/cplusplus.1444749693.txt.gz · Last modified: 2015/10/13 17:21 (external edit)