How do i return a template class from a template function?
Posted
by LoudNPossiblyRight
on Stack Overflow
See other posts from Stack Overflow
or by LoudNPossiblyRight
Published on 2010-05-25T18:55:07Z
Indexed on
2010/05/25
19:01 UTC
Read the original article
Hit count: 229
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;
}
© Stack Overflow or respective owner