recently i was testing some c++ template codes and i found one mind-boggling error. According to my research on internet in particular stackoverflow, this code is completely val
Expanding on chris' answer, the following compiles fine with both visual c++ 12.0 and g++ 4.7.2:
#include
#include
using namespace std;
template class C, class T, class U> void print(C& c)
{ (void) c; }
void test() {
vector v(5, "Yow!");
print(v);
}
However, if you really just want to output the items of a container, why not do this instead:
#include
#include
#include
using namespace std;
template< class C >
void print( C const& c )
{
for( auto const& item : c )
{
cout << item << endl;
}
}
auto main() -> int
{
vector v(5, "Yow!");
print(v);
}