Question: 40. Given the following code: #include 2using namespace std; 4 template 5class SampleTemplateClass public typedef T* iterator; // defines iterator as another name Tor type

 40. Given the following code: #include 2using namespace std; 4 template

5class SampleTemplateClass public typedef T* iterator; // defines iterator as another name

40. Given the following code: #include 2using namespace std; 4 template 5class SampleTemplateClass public typedef T* iterator; // defines iterator as another name Tor type T* 10 SampleTemplateClass (int size) : m_size (size_pArray (new T[size]) 12 13 -SampleTemplateClass() delete [] m_pArray; 16 17 iterator beginO // return type is T* (iterator is another name for T*) 19 20 21 return m_pArray; iterator end) // return type is T* (iterator isa another name for T) 24 25 return (m pArray + m size); private 30 31 32 33 ; int m size T* m_pArray; (a) How would you instantiate a SampleTemplateclass of ints, and construct an ob- ject identified by stc whose m_pArray of size 3? (b) SampleTemplateClass s begin) returns a pointer T* which element in m_pArray? (c) SampleTemplateClass s end) returns a pointer T* which element in m_pArray? d) How would you write a for-statement that iterates through the elements of stc using the iterator? Note: the members begin and end O return an object of type SampleTemplateClass::iterator; therefore, you would declare an itera- tor using the following syntax: typename SampleTemplateClass: :iterator iter stc . begin(). The prefix typename is used to communicate to the compiler that SampleTemplateClass: :iterator is a type

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!