Błąd przy użyciu szablonu funkcji

Błąd przy użyciu szablonu funkcji
JA
  • Rejestracja: dni
  • Ostatnio: dni
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:

Kopiuj
 

#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();
}

AL
  • Rejestracja: dni
  • Ostatnio: dni
1

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

JA
  • Rejestracja: dni
  • Ostatnio: dni
2

Jezu jaki wstyd!

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.