Hello, this piece of code below is taken from a public member function of a class. Can anyone please explains what is happening in line 2 and 3. For example I am not sure what these operators << i-> are?
Any help would be appreciated.
line 2: it writes value returned by i->second.getTimeRead(); to the stream tagReadTimeStream . Like with std::cout << x; http://www.cplusplus.com/doc/tutorial/basic_io/
<< is bitwise shift operator, but it is used with streams as stream insertion operator
-> is pointer member selection operator. x -> y works as (*x).y
www.cplusplus.com/doc/tutorial/classes
Look into pointers to classes section
Thanks for the reply MiNiPaa,
I read pointer to classes and I understand x -> y means member y of object pointed to by x. However, I am still confused about my code.
This piece of code is taken from a loop which I post it below. I am trying to figure out how the tagreadtime is being assigned. You said line 3 in the code below return a value to the the stream tagReadTimeStream; is this the value of i?
Also, if you see here line 4, LogStreamManager is a class and instance is a function but what about the brackets () and what this >logStatsItem(getNodeId() does?
1 2 3 4 5
for(TagIterator i = m_readTags.begin(); i != m_readTags.end(); ++i) {
ostringstream tagReadTimeStream;
tagReadTimeStream << i->second.getTimeRead();
LogStreamManager::instance()->logStatsItem(getNodeId(),
m_TAG_READ_TIME_STRING, tagReadTimeStream.str());
No it is the value, returned by member function .getTimeRead() applied to member second which is a member of object i pointing to, which is written.
LogStreamManager::instance() ← Here LogStreamManager is a class name, and instance() is a static member function. It looks like this class is singleton and instance() returns pointer to, well, instance.
On returned pointer function logStatsItem() is caled with 3 parameters: getNodeId(), m_TAG_READ_TIME_STRING, tagReadTimeStream.str()