template function

I am getting weird error when I call a template func with const argument from within a member function. The same function with same const argument works fine from within normal function!!! Here is sample

***********ClassA.h **********

template< typename T, std::size_t N > inline std::size_t size( T(&)[N] ) { return N ;}

class classA{
classA();
static const std::string units[];
}

***********classA.cpp ***********

#include "classA.h"

const std::string units[] ={"String1", "String2"};

classA::classA()
{
int len = size(units);
}


When I compile the above code I get error -
error C2893: Failed to specialize function template size(T (&)[N]) With the following template arguments: 'const std::string'

Can anyone please suggest why this might be happening.

Thanks
Pan
Try

1
2
3
template< typename T, std::size_t N > inline
std::size_t N size( T (const &)[ N ] )
{  return N; }


Topic archived. No new replies allowed.