Ok so Im just learning templates for the first time and so I was toying around creating my own template class that mimics its underlying type which is a vector. Keep in mind that the call to push_back just calls the push_back method of the underlying vector.
vector<string> sV;
sV.push_back("ha"); //ok: converts from const char[3] to string
Foo<string> fS;
fS.push_back("ha"); //error: const char[3] does not match the argument list
Is there a way I can fix this? I just want my template to feel as natural as if I'm using the real thing.
EDIT : This is basically the body of the class
template <typename T> class FooPtr;
template <typename T>
class Foo{
friend class FooPtr<T>;
public:
Foo() {data->make_shared(vector<T>); }
#ifdef INITIALIZER_LIST
Foo(initializer_list<T>);
#endif
void push_back(T &t) { data->push_back(t); }
void push_back(T &&t) { data->push_back(move(t)); }
bool empty() { if (data->size() == 0) return true; }
FooPtr<T> insert(size_t, T&);
T& operator[](size_t);
T& front();
T& back();
FooPtr<T> begin() { return FooPtr<T>(*this); }
FooPtr<T> end() { return FooPtr<T>(*this, data->size()); }
void pop_back() { data->pop_back(); }
void pop_front() { data->pop_front; }
private:
void check(const string&, size_t = 0);
shared_ptr<vector<T>> data;
};
std::move(t)should be astd::forward<T>(t).void push_back(T &&t)be picked for his call? since during overload resolution the converting constructor of the std::string is called and the std::string hence formed is an rvalue?