Question

Given the following class: template<typename T> class Storage { public: Storage(T* s):stuff(s) { } T* stuff;...

Given the following class:

template<typename T>
class Storage
{
 
public:
   Storage(T* s):stuff(s)
   {    }
   T* stuff;
 
};

Which of the following is a valid instantiation of the Storage class?  Be careful with this question.
A.

Storage s;

B.

Storage<78> s;

C.
Storage<double*> s;





D.
Storage<double> s(new double);
E.

Storage<int> s(new double);   

0 0
Add a comment Improve this question Transcribed image text
Answer #1
a valid instantiation of the Storage class is Storage<double> s(new double);

D. Storage<double> s(new double);
Add a comment
Know the answer?
Add Answer to:
Given the following class: template<typename T> class Storage { public: Storage(T* s):stuff(s) { } T* stuff;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following template class: template <typename T> class ArrayOfTen { public: ArrayOfTen(); ~ArrayOfTen(); void insert(T);...

    Consider the following template class: template <typename T> class ArrayOfTen { public: ArrayOfTen(); ~ArrayOfTen(); void insert(T); void printAll(); private: T * array; int size; } a. When the array is first created, it should allocate memory for 10 items. Size should be zero. Write the constructor: b. When ArrayOfTen::insert(T) is called, the new item should be added to the array, and size should increase by one. If the array already has 10 items, then it should throw an exception. Write...

  • #include <iostream> using namespace std; template <typename Item> class MyArray{ private:    Item *myarray;    int...

    #include <iostream> using namespace std; template <typename Item> class MyArray{ private:    Item *myarray;    int size;    int used;    void doubleSize(); public:    MyArray();    ~MyArray();    int length();    void insertHead(Item i);    void insertTail(Item i);    void deleteHead();    void deleteTail();    void sortAscending();    void sortDescending();    Item operator [](int i){        return myarray[i];    } }; template <typename Item> MyArray<Item>::MyArray(){    size = 5;    used = 0;    myarray = new Item[size];...

  • //C++ program #include<iostream> using namespace std; template<typename T> class list{    private:        T*arr;   ...

    //C++ program #include<iostream> using namespace std; template<typename T> class list{    private:        T*arr;        int size;        int capacity;               void resize(){            capacity*=2;            T * newArr = new T[capacity];            for(int i=0;i<size;i++){                newArr[i] = arr[i];            }            delete(arr);            arr = newArr;                   }           public:       ...

  • Given the following code: #ifndef TREE_H #define TREE_H #include <iostream> #include "TreeNode.h" template< typename NODETYPE > class Tree { public: Tree() : rootPtr( nullptr ) {}...

    Given the following code: #ifndef TREE_H #define TREE_H #include <iostream> #include "TreeNode.h" template< typename NODETYPE > class Tree { public: Tree() : rootPtr( nullptr ) {} void insertNode( const NODETYPE &value ) { insertNodeHelper( &rootPtr, value ); } void preOrderTraversal() const { preOrderHelper( rootPtr ); } void inOrderTraversal() const { inOrderHelper( rootPtr ); } private: TreeNode< NODETYPE > *rootPtr; void insertNodeHelper( TreeNode< NODETYPE > **ptr, const NODETYPE &value ) { if ( *ptr == nullptr ) * ptr = new...

  • Submissions) Part A Type and run the Array class template discussed in lecture (Templates notes). Modify...

    Submissions) Part A Type and run the Array class template discussed in lecture (Templates notes). Modify the class by adding sort member function (refer to Algorithm Analysis notes for sorting algorithms) Sample usage: a. sort(); Add the needed code in main to test your function. template <class T> 1/you can use keyword typename instead of class class Array { private: T *ptr; int size; public: Array(T arr[], int s); void print(); template <class T> Array<T>:: Array (T arr[], int s)...

  • Please use template <typename T>. This is a C++ Data Structures Question. Problem 5. (20 pts...

    Please use template <typename T>. This is a C++ Data Structures Question. Problem 5. (20 pts total) Write the erase functions for the Mtree class that deletes every node in the Mtree. Note there should be two erase functions. The irst is in the e second is a recursive function in the private section that is called by the function in the public ar Root.) ree-

  • #ifndef HEAP_H_ #define HEAP_H_ namespace cse { template<typename dtype> class heap { public: /** TO DO::...

    #ifndef HEAP_H_ #define HEAP_H_ namespace cse { template<typename dtype> class heap { public: /** TO DO:: default constructor perform new to reserve memory of size INITIAL_CAPACITY. set num_items = 0; */ heap() { // write your code here }; /** Create a heap from a given array */ heap(dtype *other, size_t len) { // write your code here }; /** copy constructor copy another heap to this heap. */ heap(const heap<dtype> &other) { //write your code here }; /** Accessor...

  • e fellowing class declaration to answer the questionist below class WeatherStation public emp, double wind, string...

    e fellowing class declaration to answer the questionist below class WeatherStation public emp, double wind, string wind dir, double prediplk void void void int Winda int getTempo double getWindSpeed) : string getWind Direction): double getPrecipitation: void setTemp(int t void setWindData(double w, string dir): void setPrecip(double pl printTempO private int temperature double windSpeed, precipitation string windDir method 14) 14) Refer to the class declaration above. Which of the following methods is an accessor A) int WindChillo: C) WeatherStation: B) void setPrecipO...

  • QUESTION 7 In the template prefix, template<class T>, what kinds of variables is the parameter T?...

    QUESTION 7 In the template prefix, template<class T>, what kinds of variables is the parameter T? T must not be a class T can be any type, whether build into C++ or programmer defined, but subject to restrictions T must be a type built into C++ such as int or double OT must be a class QUESTION 10 Which statement is incorrect? Placing data on a stack is called push O A stack is a first-in-first-out data structure O A...

  • can someone please fix this error in the stack file at line 18 ( class Stack2:public...

    can someone please fix this error in the stack file at line 18 ( class Stack2:public Stack { ) this is thew error ----> expected class name before '{' token Queue.h --> #include "Stack.hpp" template <typename ITEM> class Queue { private: ITEM item; Stack <ITEM> * s1= new Stack<ITEM>; Stack <ITEM> * s2= new Stack<ITEM>; public: Queue(){}; bool enqueue (ITEM item); bool dequeue (ITEM &item); bool check = true; ~Queue(); }; //this is the class which contains the functions of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT