I have a problem with a compiler error, take a look at this code:
template<class T>
struct MyStruct
{
};
template<>
struct MyStruct<int>
{
typedef int* type;
};
template<class T>
void foo(const typename MyStruct<T>::type myType)
{
}
int main()
{
const int* ptr = NULL;
foo<int>(ptr);
return 0;
}
The problem is that the compiler is ignoring the 'const' on foo function, making the call to foo illegal (const int* to int*).
Severity Code Description Project File Line Suppression State Error C2664 'void foo(const MyStruct::type)': cannot convert argument 1 from 'const int *' to 'const MyStruct::type'
I have tested the following code in Visual studio's and gcc's 5.3 complier, both of them dropping the same error.
Does the complier doing this on purpose? why is this happening?