| murukesh (3) | |||
|
I'm a C++ beginner, currently studying stacks, with a basic knowledge of both C and C++. I am using Code::Blocks as my IDE with the MingW compiler that comes along. I have a question regarding the operators >> and <<. What would happen if both the operands are streams? say something like:
The code of line 4 compiles fine, and executes too, giving me the answer: [code] F:\College>test 0x445468 F:\College> [\code] Whereas line 5 gives me an error stating ambigous overload for operator>>. Further, I tried a simple variation: I changed 'cin' in line 4 to '&cin'. The resulting execution gave me a slightly different answer: 0x445460 Could anyone explain to me: a) the significance of 0x445468? b) why line 4 doesn't generate an error? c) why line 5 does? d) why changing cin to &cin decreased the output by 8? | |||
|
|
|||
| helios (10258) | |
|
a. It's a fortuitous memory address. Specifically, the location the object std::cin occupied during that particular run of the program. b. There's an overload for operator<<() which takes an std::ostream and a pointer to a stream function (I can't remember the exact signature, but I think it has the same signature as std::endl). c. I'd need to see the error to answer this question, but I can't be bothered to try it myself. d. Actually, I don't know. I think it should give the same result. | |
|
|
|
| murukesh (3) | |||
|
a. Yet different runs of the program after rebuilding while occasionally changing cin to &cin still yield the same numbers. b. CodeBlocks says that the ambiguities are caused by matches to the following:
While I do understand templates a bit, this goes way over my head. Thanks. | |||
|
|
|||