Question: I'm programming in c++ using sublimetext3. My program has a superclass called Array, and a subclass called IntArray. Both classes are template classes. Currently, I'm

I'm programming in c++ using sublimetext3. My program has a superclass called Array, and a subclass called IntArray. Both classes are template classes. Currently, I'm having trouble compiling the program. It keeps giving me an error provided below. Also below that are my source files. Fix it so that the code in main.cpp works.

Error:

In file included from main.cpp:3:

./Array.h:18:19: error: C++ requires a type specifier for all declarations

template Array(T s) throw() {

^

./Array.h:19:2: error: use of undeclared identifier 'size'

size = s;

^

In file included from main.cpp:4:

./IntArray.h:5:31: error: use of undeclared identifier 'T'

class IntArray : public Array {

^

./IntArray.h:5:34: error: expected class name

class IntArray : public Array {

^

./IntArray.h:8:11: error: unknown type name 'T'

IntArray(T s) throw();

^

./IntArray.h:18:27: error: expected unqualified-id

template IntArray::IntArray(T s) throw() : Array(s) {

^

6 errors generated.

main.cpp

#include #include #include "Array.h" #include "IntArray.h"

int main(int argc, char** argv) {

// make an array of doubles with size 10 Array iA(10);

// get the size of the array std::cout<< "The size of IntArray is" <

} // end of main

Array.h

#ifndef ARRAY_H #define ARRAY_H

template class Array { private: T size;

public: Array(T s) throw(); virtual ~Array() throw(); // getter method T getSize() const throw(); };

// constructor: initialize the size private field in Array class template Array(T s) throw() { size = s; }

// destructor template Array::~Array() throw() {

}

// getter methods: returns size template T Array::getSize() const throw() { return size; }

#endif

IntArray.h

#ifndef INTARRAY_H #define INTARRAY_H #include "Array.h"

class IntArray : public Array {

public: IntArray(T s) throw(); virtual ~IntArray() throw(); //int getSize() const throw(); };

// constructor // call the Array super class's constructor and initialize it's private member with the // input from the IntArray constructor template IntArray::IntArray(T s) throw() : Array(s) {

}

// desctructor template IntArray::~IntArray() throw() {

}

#endif

Makefile

all:main

main.o: main.cpp Array.h IntArray.h g++ -c -Werror main.cpp

main: main.o g++ -o main main.o

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!