[Dev-C++] Using Templates & Constructors
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: w0rldd0m <dg...@wo...> - 2004-10-26 21:10:59
|
Hi,
Thanks in advance for any help you can offer.
Im trying to use a template class and I keep making mistakes. So now I am
trying to create an isolated case, but its still broke.
Please can anyone help me solve this? Here are the compiler errors that I
get:
_______________
\myFolder\myClass.cpp In constructor `myClass<Type>::myClass(const Type&)':
7 \myFolder\myClass.cpp syntax error before `;' token
\myFolder\Makefile.win [Build Error] [myClass.o] Error 1
_______________
Here is my main.cpp code:
_______________
#include <iostream>
#include <stdlib.h>
#include "myClass.h"
using namespace std;
int main(int argc, char *argv[])
{
myClass<int> test(5);
system("PAUSE");
return 0;
}
__________________
Here is my myClass.h code:
__________________
#include <iostream>
#ifndef H_MYCLASS
#define H_MYCLASS
template<class Type>
class myClass
{
public:
//Default Constructor
myClass(const Type &item);
protected:
Type count;
};
#endif
_____________________
Lastly, here is my myClass.cpp code:
_____________________
#include <iostream>
#include "myClass.h"
template<class Type>
myClass<Type>::myClass(const Type &item) //default constructor
{
count = new Type item;
}
______________________
Best regards,
Dane
|