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.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
^
6 errors generated.
main.cpp
#include
int main(int argc, char** argv) {
// make an array of doubles with size 10 Array
// 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 public: Array(T s) throw(); virtual ~Array() throw(); // getter method T getSize() const throw(); }; // constructor: initialize the size private field in Array class template // destructor template } // getter methods: returns size template #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 } // desctructor template } #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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started