Join TSR now and chat about whatever you’re intoSign up now

C++ questions Watch

    Offline

    0
    ReputationRep:
    (Original post by INTit)
    It's a class with a templated, overloaded '<' operator which allows access to the output stream. Ok maybe there's a good reason tutorials don't go into too much detail explaining cout lol.
    The way objects are usually called is with the objects name and then call a function from the class.

    Putting the cout object as a template stops you from having to put the object name and then calling the function to make this work, allowing you to just use the word cout and not having to call it from a object reference if that makes any sense? As far as I understand this of course.
    Offline

    2
    ReputationRep:
    (Original post by j.smith1981)
    The way objects are usually called is with the objects name and then call a function from the class.

    Putting the cout object as a template stops you from having to put the object name and then calling the function to make this work, allowing you to just use the word cout and not having to call it from a object reference if that makes any sense? As far as I understand this of course.
    cout is actually an object itself

    http://www.cplusplus.com/reference/iostream/cout/

    It's an object of type "ostream". In the ostream class the "<<" operator is defined which is basically equivalent to a function but with different syntax. There are different versions (overloads) of this operator for different data types.

    The implementation of the ostream class may use templates, I'm not sure. But if you're just using it you probably don't need to worry about how cout is implemented.
 
 
 
Poll
Is GoT overrated?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Quick reply
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.