functions???

Started by
14 comments, last by BattleGuard 20 years, 11 months ago
k thx

BattleGuard

Whenever I try to find a better signature than this... Well, I can''t... This is it, Sorry...
Advertisement
first of all, "cout" is not a function, it is an object name.

the leftshift operator, "<<", is actually the function here. when you write,
 cout << "hi" << endl; 

you are actually using a stream operator, which you will learn about when you study objects, the prefix version looks like this:
 cout.operator<< ("hi"); //call the output function and send "hi" cout.operator<< (endl); //call the output function and send "\n" 


got it?

objects, as you will learn, can have their own operators defined, like <<, +, -, [], (), etc.

I, too, am new to C++ and have a question about functions. I don''t understand why the definition of the function comes after the actual program. Any clarification would be much appreciated.
Actually the definition should have all come later... Everything, only that the compiler can know that the function exists so it doesn''t give an error something like: "Undefined function" or something...

BattleGuard

Whenever I try to find a better signature than this... Well, I can''t... This is it, Sorry...
quote:Original post by Annatar
I, too, am new to C++ and have a question about functions. I don''t understand why the definition of the function comes after the actual program. Any clarification would be much appreciated.


It doesn''t matter when the definition of the function takes place in code as long as you have the prototype first. This way the compiler knows that there will be a function called Foo(), with the appropriate arguements and return. Hope that helps.
Ok thanks alot!

This topic is closed to new replies.

Advertisement