Bruno
Bruno

Reputation: 19

How to create classes with template in C++

I'm trying to create a template class, but some erros has ocurred when i define the methods in the array.cpp file

here are the source code files(i can't post more than 1 hiperlink >.<):

main.cpp: pastebin.com/DxLFDhnc

array.hpp: pastebin.com/MmCAj3Ci

array.cpp: pastebin.com/32czzPBc

errors:

main.cpp undefined reference to `Array::Array(unsigned int)'

main.cpp undefined reference to `Array::operator[](unsigned int)'

main.cpp undefined reference to `Array::operator[](unsigned int)'

main.cpp undefined reference to `Array::operator[](unsigned int)'

main.cpp undefined reference to `Array::length()'

main.cpp undefined reference to `Array::operator[](unsigned int)'

main.cpp undefined reference to `Array::~Array()'

main.cpp undefined reference to `Array::~Array()'

=== Build finished: 8 errors ===

Upvotes: 0

Views: 130

Answers (2)

greatwolf
greatwolf

Reputation: 20838

It would help if you posted some code that's giving the error. But from the error messages you're getting, I would say you're class template isn't fully defined in the source unit that instantiates an instance of it. Look at nanothief's link for more info.

Upvotes: 0

David Miani
David Miani

Reputation: 14668

This should answer your question: http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12

Upvotes: 2

Related Questions