MESSAGE
DATE | 2011-06-13 |
FROM | Ruben Safir
|
SUBJECT | Subject: [NYLXS - HANGOUT] C++ Workshop Quiz
|
Looking at the following probram and without running it, what is its output.
#include
class A { public: explicit A(int n = 0) : m_n(n) { }
A(const A& a) { this->m_n = a.m_n; ++m_copy_calls; }
public: A& operator=(const A& a) { this->m_n = a.m_n; return *this; }
public: static int m_copy_calls;
private: int m_n; };
int A::m_copy_calls = 0;
A f(const A& a) { return a; }
A g(const A a) { return a; }
int main() { A a; std::cout << A::m_copy_calls; A b = a; std::cout << A::m_copy_calls; A c(a); std::cout << A::m_copy_calls;
b = g(c); std::cout << A::m_copy_calls;
const A& d = f(c); std::cout << A::m_copy_calls << std::endl;
return 0; }
This is VERY similar to a question I saw on an employment examination.
Ruben
|
|