I'm trying to use different types of containers of different types with the same function but couldn't convince my compiler. Here are some of the things I have tried:
#include <iostream>
#include <vector>
#include <list>
using namespace std;
// error: expected a qualified name after 'typename'
template<typename C<T>>
void func1() {
C<T> c;
c.push_back(new T);
}
// error: expected a qualified name after 'typename'
template<typename C<typename T>>
void func2() {
C<T> c;
c.push_back(new T);
}
// error: expected a qualified name after 'typename'
template<typename C<template <typename T>>>
void func3() {
C<T> c;
c.push_back(new T);
}
int main(int argc, char *argv[]) {
func1<vector<int>>();
func1<list<float>>();
func2<vector<int>>();
func2<list<float>>();
func3<vector<int>>();
func3<list<float>>();
return 0;
}
Is this possible in C++?