Can someone help me implement enough functionality my my_vector.cpp file to appease the basic main.cpp? I was given the main.cpp and my_vector.h files. I also cannot edit the main.cpp and my_vector.h files.
#ifndef MY_VECTOR_H
#define MY_VECTOR_H
// my_vector.h
usingnamespace std;
template <class T>
class my_vector
{
public:
// Constructors / Destructor
my_vector();
// Constructor with initial size
my_vector(unsignedint size);
// Constructor with initial size -- set all initial spaces to initial param
my_vector(unsignedint size, const T & initial);
// Copy constructor
my_vector(const my_vector & v);
~my_vector();
// Return capacity of vector (in elements)
int capacity() const;
// Return the number of elements in the vector
unsignedint size() const;
// Return true if vector has no elements
bool empty() const;
// Add a new element to the end of the backing array
// Don't forget to resize if needed!
void push_back(const T & value);
// Remove the last element (don't return it)
void pop_back();
// Adjust capacity (make more space as needed)
void reserve(unsignedint new_capacity);
// Resize vector (even if that means making it smaller)
void resize(unsignedint new_size); // adjust size
/* Overloaded operators */
// Return a *reference* to numbered element
T & operator [ ](unsignedint index) const;
private:
unsignedint my_size;
unsignedint my_capacity;
T * buffer;
};
/* put all your code in my_vector.cpp */
#include "my_vector.cpp"
#endif
my_vector.cpp:7: error: ‘template<class T> class my_vector’ used without template parameters
my_vector.cpp:7: error: ISO C++ forbids declaration of ‘my_vector’ with no type
my_vector.cpp: In function ‘int my_vector()’:
my_vector.cpp:7: error: ‘int my_vector()’ redeclared as different kind of symbol
my_vector.h:8: error: previous declaration of ‘template<class T> class my_vector’
my_vector.cpp: At global scope:
my_vector.cpp:12: error: ‘template<class T> class my_vector’ used without template parameters
my_vector.cpp:12: error: ISO C++ forbids declaration of ‘my_vector’ with no type
my_vector.cpp: In function ‘int my_vector(unsignedint)’:
my_vector.cpp:12: error: ‘int my_vector(unsignedint)’ redeclared as different kind of symbol
my_vector.h:8: error: previous declaration of ‘template<class T> class my_vector’
my_vector.cpp: At global scope:
my_vector.cpp:16: error: ‘template<class T> class my_vector’ used without template parameters
my_vector.cpp:16: error: ISO C++ forbids declaration of ‘T’ with no type
my_vector.cpp:16: error: expected ‘,’ or ‘...’ before ‘&’ token
my_vector.cpp:16: error: ISO C++ forbids declaration of ‘my_vector’ with no type
my_vector.cpp: In function ‘int my_vector(unsignedint, int)’:
my_vector.cpp:16: error: ‘int my_vector(unsignedint, int)’ redeclared as different kind of symbol
my_vector.h:8: error: previous declaration of ‘template<class T> class my_vector’
my_vector.cpp: At global scope:
my_vector.cpp:20: error: ‘template<class T> class my_vector’ used without template parameters
my_vector.cpp:20: error: ISO C++ forbids declaration of ‘my_vector’ with no type
my_vector.cpp:20: error: expected ‘,’ or ‘...’ before ‘&’ token
my_vector.cpp:20: error: ISO C++ forbids declaration of ‘my_vector’ with no type
my_vector.cpp: In function ‘int my_vector(int)’:
my_vector.cpp:20: error: ‘int my_vector(int)’ redeclared as different kind of symbol
my_vector.h:8: error: previous declaration of ‘template<class T> class my_vector’
my_vector.cpp: At global scope:
my_vector.cpp:24: error: expected constructor, destructor, or type conversion before ‘::’ token
my_vector.cpp:28: error: ‘template<class T> class my_vector’ used without template parameters
my_vector.cpp:28: error: non-member function ‘int capacity()’ cannot have cv-qualifier
my_vector.cpp:33: error: ‘template<class T> class my_vector’ used without template parameters
my_vector.cpp:33: error: non-member function ‘unsignedint size()’ cannot have cv-qualifier
my_vector.cpp:39: error: ‘template<class T> class my_vector’ used without template parameters
my_vector.cpp:39: error: non-member function ‘bool empty()’ cannot have cv-qualifier
my_vector.cpp:43: error: ‘template<class T> class my_vector’ used without template parameters
my_vector.cpp:43: error: ISO C++ forbids declaration of ‘T’ with no type
my_vector.cpp:43: error: expected ‘,’ or ‘...’ before ‘&’ token
my_vector.cpp:47: error: ‘template<class T> class my_vector’ used without template parameters
my_vector.cpp:51: error: ‘template<class T> class my_vector’ used without template parameters
my_vector.cpp:56: error: ‘template<class T> class my_vector’ used without template parameters
main.cpp:11: warning: first argument of ‘int main(char**)’ should be ‘int’
main.cpp:11: warning: ‘int main(char**)’ takes only zero or two arguments
make: *** [main] Error 1
OK i put that in. I guess my teacher forgot to put that piece in. Can you check my my_vector.cpp file to see what i need to appease the basic main.cpp? thank you so much for help.