I'm trying to work with a function outside the class vector inside the vector class.
inside the main when I'm calling the same func it worked fine but when I call it inside the vector class, I get this error
➜ ft_containers git:(main) ✗ clang++ main.cpp -g
In file included from main.cpp:17:
In file included from ./containers/../colors.hpp:24:
./containers/vector.hpp:139:5: error: use of undeclared identifier 'PrintVecData'
PrintVecData<value_type>(*this);
^
./containers/vector.hpp:139:18: error: unexpected type name 'value_type': expected expression
PrintVecData<value_type>(*this);
^
2 errors generated.
➜ ft_containers git:(main) ✗
color.hpp
#ifndef COLORS_H
#define COLORS_H
# define GREEN "\e[1;32m"
# define RESET "\e[0m"
# define RED "\e[1;91m"
# define CYAN "\e[1;36m"
# define YELLOW "\e[1;33m"
# define PURPLE "\e[1;35m"
# define BLUE "\e[1;34m"
#include "containers/vector.hpp"
template<typename T>
void PrintVecInfo(ft::vector<T>& ft_vec, std::vector<T>& std_vec)
{
std::cout << "ft::capacity : " << ft_vec.capacity() << std::endl;
std::cout << "ft::size : " << ft_vec.size() << std::endl;
std::cout << "ft::max_size : " << ft_vec.max_size() << std::endl;
std::cout << "std::capacity : " << std_vec.capacity() << std::endl;
std::cout << "std::size : " << std_vec.size() << std::endl;
std::cout << "std::max_size : " << std_vec.max_size() << std::endl;
}
template<typename T>
void PrintVecData(ft::vector<T>& ft_vec, std::vector<T> std_vec = std::vector<T>())
{
std::cout << "ft: ";
for (size_t i = 0; i < ft_vec.size(); i++)
std::cout << "|" << *(ft_vec.begin() + i) << "|" ;
std::cout << std::endl << "std: ";
for (size_t i = 0; i < std_vec.size(); i++)
std::cout << "|" << *(std_vec.begin() + i) << "|" ;
std::cout << std::endl;
PrintVecInfo<T>(ft_vec, std_vec);
}
#endif
the "containers/vector.hpp" file is :
#include "iterator.hpp"
#include "utils.hpp"
#include <string>
#include <iostream>
#include <algorithm>
namespace ft
{
template < class T, class Allocator = std::allocator<T> >
class vector
{
public: /* Modifiers */
void insert (iterator position, size_type n, const value_type& val)
{
difference_type diff = this->end() - position;
difference_type posIndex = position - this->begin();
if (this->size() + n > this->capacity())
{
if (this->size() + n > this->capacity() * 2)
this->reserve(this->size() + n);
else
this->reserve(this->capacity() * 2);
}
iterator it = this->begin() + posIndex;
for (size_t i = 0; i < diff; i++)
{
*(it + n) = *(it);
it++;
}
it = this->begin() + posIndex;
for (size_t i = 0; i < n; i++)
*(it + i) = val;
PrintVecData<value_type>(*this) <==== here
this->_size += n;
};
}
when I call PrintVecData<value_type>(vec)
in main it work fine with no problem but when I call the same function inside the vector
class I the error above;