How do i return a template class from a template function?
- by LoudNPossiblyRight
It looks logical but for some reason when i uncomment the last cout line, this code does not compile. How do i return a template class? What do i have to do to this code to make it work?
#include<iostream>
using namespace std;
template <int x>
class someclass{
public:
int size;
int intarr[x];
someclass():size(x){}
};
template<int x, int y>
int somefunc(someclass<x> A, someclass<y> B){
return ( A.size > B.size ? A.size : B.size);
}
template<int x, int y, int z>
someclass<x> anotherfunc(someclass<y> A, someclass<z> B){
return ( A.size > B.size ? A : B);
}
int main(){
someclass<5> A;
someclass<10> B;
cout << "SIZE = " << somefunc(A,B) << endl;
//cout << "SIZE = " << (anotherfunc(A,B)).size << endl; //THIS DOES NOT COMPILE
return 0;
}