Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

Define marketing.

Answered: 1 week ago

Question

What are the traditional marketing concepts? Explain.

Answered: 1 week ago

Question

Define Conventional Marketing.

Answered: 1 week ago

Question

Define Synchro Marketing.

Answered: 1 week ago