We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,991 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
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;
 }


};
2
Contributors
1
Reply
4 Hours
Discussion Span
1 Year Ago
Last Updated
2
Views
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

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0617 seconds using 2.7MB