Start New Discussion Reply to this Discussion C++ Array template error!!!
I have errors for the template can any1 see anything wrong???
//Array.h
//Header file for Array.cpp.
class Array
{
private:
//Template for use with the Array's data type.
//Member Variables.
int size;
int grow_size;
int num_elements;
public:
//Functions.
template<class Datatype>
int m_size;
Datatype* m_array;
//Consturctor.
Array( int p_size)
{
m_array= new Datatype[p_size];
size= p_size;
}
//Destructor.
~Array()
{
if( m_array!= 0 )
delete[] m_array;
m_array= 0;
}
};
Related Article: Help with a Template Class Array
is a C++ discussion thread by pwnerboy that has 4 replies, was last updated 1 year ago and has been tagged with the keywords: array, c++, college, easy.
pendo826
Light Poster
44 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Maybe it is not really the case, but IMO the whole class should be a template, not just one function or member...
Like:
template <class T>
class Array{
public:
T* m_array;
}
Although it's 3:30 am and I might've gotten this wrong.
jaskij
Junior Poster
106 posts since Oct 2011
Reputation Points: 55
Solved Threads: 19
Skill Endorsements: 0
© 2013 DaniWeb® LLC
Page rendered in 0.0617 seconds
using 2.7MB