Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ beginner question

Tags:

c++

I am in the process of learning C++ in order to understand some open source code I have been given.

I came across a line as follows:

cmd << '\n'

I assumed that "cmd" must be some kind of special receptor for a stream, perhaps a string - but on further investigation I found that "cmd" was an entire class with assorted data and functions. This has completely confused me. Why doesn't the code look like this:

cmd.stringpart << '\n'

Can someone tell me what's going on, or suggest an article for me to take a look at.

CORRECTION: cmd is an instance of a class rather than the class itself.

like image 656
Mick Avatar asked Dec 01 '22 04:12

Mick


1 Answers

In C++, you can overload operators. In this case it seems to be used to make some Cmd class behave like a stream.

like image 156
Sebastian Negraszus Avatar answered Dec 03 '22 16:12

Sebastian Negraszus