0

I'm new at C++. I'm trying to re-implement the container vector. So far I have had a header file named vector.hpp:

    #ifndef VECTOR_HPP
    #define VECTOR_HPP
    
    #include <iostream>
    
    namespace ft
    {
        template <typename T>
        class vector
        {
            public:
                vector(void);
                ~vector(void);
            private:
                unsigned int _size;
        };
    } 
    #endif

And a source file named vector.cpp

#include "vector.hpp"

template <typename T>
ft::vector<T>::vector(void): _size(0)
{ std::cout << "Constructor called\n";}

template <typename T>
ft::vector<T>::~vector(void) 
{ std::cout << "Deconstructor called\n";}

Then my main.cpp

#include <iostream>
#include "vector.hpp"

int main(void)
{
    ft::vector<int> vect_int;
    return(0);
}

Then I compile with: c++ main.cpp vector.cpp and it gives the error which I don't know why. Thanks for your help!

/tmp/ccVgRWqs.o: In function `main':
main.cpp:(.text+0x20): undefined reference to `ft::vector<int>::vector()'
main.cpp:(.text+0x31): undefined reference to `ft::vector<int>::~vector()'
collect2: error: ld returned 1 exit status
Snow_Ball
  • 55
  • 7
  • 2
    Is it really necessary to down vote my question? I don't even know what's kind of problem is it so how can I know to search for "templates cannot be implemented in header file"? It's impossible to know what you don't know. You can always just close my question instead of down voting it. – Snow_Ball Nov 30 '21 at 15:50

0 Answers0