Jump to content
  • Advertisement
Sign in to follow this  

[c++] Strange error - Unresolved External @ Link time w/ Template

This topic is 2805 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all I am experiencing a very strange error, compliler says

Error 1 error LNK2019: unresolved external symbol "private: void __thiscall Vec<int>::create(void)" (?create@?$Vec@H@@AAEXXZ) referenced in function "public: __thiscall Vec<int>::Vec<int>(void)" (??0?$Vec@H@@QAE@XZ) c:\practice\vec\vec\main.obj vec

and here is my source code


#ifndef GUARD_vec_h
#define GUARD_vec_h

#include <memory>
#include <allocators>

template <class T> class Vec {
typedef T* iterator;
typedef const T* const_iterator;
typedef size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef T& ref;
typedef const T& const_ref;

Vec() { create(); }
explicit Vec(size_type n, const T& t= T()) { create(n,t); }
~Vec() { uncreate(); }
Vec(const Vec& v) { create(v.begin(), v.end()); }

size_type size() const { return avail - data; }
void push_back(const T& val) {
if(avail == limit) grow();
T& operator[](size_type i) { return data; }
Vec& operator=(const Vec&);

const T& operator[] (size_type i) const {return data; }

iterator begin() { return data; }
const_iterator begin() const { return data; }

iterator end() { return limit; }
const_iterator end() const { return limit; }
void create();
void create(size_type, const T&);
void create(const_iterator, const_iterator);

iterator data;
iterator avail;
iterator limit;

std::allocator<T> alloc;

void uncreate();

void grow();
void unchecked_append(const T&);



#include "vec.h"

template <class T>
Vec<T>& Vec<T>::operator=(const Vec& rhs) {
if(&rhs != this) {

create(rhs.begin(), rhs.end());
return *this;

template <class T>
void Vec<T>::create() { data = avail = limit = 0; }

template <class T>
void Vec<T>::create(size_type n, const T& val) {
data = alloc.allocate(n);
limit = avail = data + n;

template <class T>
void Vec<T>::create(const_iterator i, const_iterator j) {
data = alloc.allocate(j-i);
limit = avail = std::unitialized_copy(i,j,data);

template <class T>
void Vec<T>::uncreate() {
if(data) {
iterator it = avail;

while(it != data)

data = limit = avail = 0;

template <class T>
void Vec<T>::grow() {
size_type new_size = max(2* (limit - data), ptrdiff_t(1));

iterator new_data = alloc.allocate(new_size);
iterator new_avail = std::uninitialized_copy(data,avail,new_data);


data = new_data;
avail = new_avail;

limit = data + new_size;

template <class T>
void Vec<T>::unchecked_append(const T& val) {

and just the entry point

Any clue why I am getting unresolved linking issues?

[Edited by - DimitriA on October 17, 2010 3:28:03 AM]

Share this post

Link to post
Share on other sites
Using templates across two files creates linker errors. If you want to use templates, you have to move all function definitions back together with the declarations.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!