Błąd przy użyciu szablonu funkcji

0

Podejrzewam, że problem do rozwiązania jest trywialny, niestety ja już straciłem cierpliwość. Przy próbie kompilacji występuje o to takie komunikaty:

error C2440: 'return' : cannot convert from 'std::basic_ostream<_Elem,_Traits>' to 'int'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> szablonfunkcji.cpp(17) : see reference to function template instantiation 'T f<int>(T *)' being compiled
1> with
1> [
1> T=int
1> ]
1>
1>Build FAILED.

TO MÓJ KOD:

 

#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <cstdlib>
using namespace std;

template < class T >
T f(T* arg){
T a = *arg;
return cout << a << endl;
}

int main()
{
int a = 221;
int* a2 = &a;
f(a2);
getch();
}

1

problem jest bardzo trywialny, nie wiem od kiedy "cout << a << endl;" zwraca inta..

2

Jezu jaki wstyd!

1 użytkowników online, w tym zalogowanych: 0, gości: 1