// B2.10.cpp : Defines the entry point for the application. // // Given the declarations: // // template class B { … private: const T t; } // class C : public B { … private: const int len; } // // write a constructor for B that takes a T argument. // Write a constructor for C that sets len to the length of its base’s // string argument. where is C's string argument created? You may assume // that the only data members are the ones shown. #include "stdafx.h" #include using namespace std; template class B { public: //// first part of answer /////// B(const T& targ) : t(targ) {} ///////////////////////////////// virtual void say() { cout << "\n B's data member = " << t; } private: const T t; }; class C : public B { public: //// second part of answer ///////////////////////////////// C(const string &s) : B(s), len((int)s.size()) {} //////////////////////////////////////////////////////////// virtual void say() { B::say(); cout << "\n C's data member = " << len; } private: const int len; }; ostream& operator<<(ostream& out, const string &s) { out << s.c_str(); return out; } int _tmain(int argc, _TCHAR* argv[]) { std::cout << "\n Exam B2 - Question #10 " << "\n ========================\n"; C c("Peter Piper picked a peck of pickled peppers"); c.say(); cout << "\n\n"; return 0; }