I’m trying to understand why the following code doesn’t compile.
class X
{
public:
template< typename T >
void set( T & val )
{
}
};
int main( int c, char *v[] )
{
X x;
x.set( new int( 99 ) ); // 15
}
On my solaris compiler I get the following error.
"x.cpp", line 15: Error: Could not find a match for X::set<X::T>(int*) needed in main(int, char**).
I can’t work out why the compiler woudln’t take the reference of a pointer to an int and pass the type “T” as “int *”
It can, but that’s a temp 😉
and you can’t bind it to a non-
constreference.Same reason why this would work:
here,
yis no longer a temporary.