This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
c_brain_teasers [2010/09/02 10:16] Jan Stancek created |
c_brain_teasers [2015/10/05 16:07] Jan Stancek |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <sxh c> | ||
+ | #include <stdlib.h> | ||
+ | #include <stdio.h> | ||
+ | class B | ||
+ | { | ||
+ | public: | ||
+ | B(int b) : m_b(b) {} | ||
+ | operator int() | ||
+ | { | ||
+ | return m_b; | ||
+ | } | ||
+ | |||
+ | int operator()() | ||
+ | { | ||
+ | return m_b*2; | ||
+ | } | ||
+ | |||
+ | private: | ||
+ | int m_b; | ||
+ | }; | ||
+ | |||
+ | class A | ||
+ | { | ||
+ | public: | ||
+ | A(int i) | ||
+ | { | ||
+ | printf("Output is: %d\n", i); | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | int k = 6; | ||
+ | A a( B(k) ); | ||
+ | |||
+ | // what is the output of this program? | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </sxh> |